# I know that there is some standard way to do this, but I have not # read it yet. # analyze options while ($#ARGV > -1 && $ARGV[0] =~ /^-/) { my $o = shift @ARGV; # To remove a file called `-f' in the current # directory, you could type either # rm -- -f # or # rm ./-f last if $o eq '--'; if ($o !~ /^--/ and length($o) > 2) { unshift @ARGV, ("-".substr($o,2)); $o = substr($o,0,2); } # -d, --directory # unlink directory, even if non-empty (super-user only) if ($o eq '-d' or $o eq '--directory') { die "option not implemented" } # -f, --force # ignore nonexistent files, never prompt elsif ($o eq '-f' or $o eq '--force') { $option_force = 1 } # -i, --interactive # prompt before any removal elsif ($o eq '-i' or $o eq '--interactive') { $option_force = '' } # -r, -R, --recursive # remove the contents of directories recursively elsif ($o eq '-r' or $o eq '-R' or $o eq '--recursive') { $option_recursive = 1 } # -v, --verbose # explain what is being done elsif ($o eq '-v' or $o eq '--verbose') { $option_verbose = 1 } # --help display this help and exit elsif ($o eq '--help') { print &help(); exit 0; } # --version # output version information and exit elsif ($o eq '--version') { print "rm in Perl, (c) Vlado Keselj, version 1.0"; exit 0; } else { die "$0: illegal option -- $o\nusage: rm [-fiRrv] file ...\n" } }