In article <[EMAIL PROTECTED]>, Arashi wrote: > Kevin Pfeiffer wrote: [...] > I have a couple of questions about your script, if you don't mind > explaining. I'm a newbie, so pls. bear with me if my questions sound > really obvious...
So am I and I know the feeling (but this list takes good care of those interested in learning Perl). > For this type of problem, is it better to use subroutines like what > you've done below, than use switch/if-elsif? I don't know; I want to look at switch myself sometime. > The second line is "my $file = '';" How does the empty string work? I don't think it was needed here. "my $file;" should be fine I believe. > Inside the if block, there are statements like "empty_trash($trash_path) > if $1 eq 'e';". Does $1 refer to $ARGV[0]? (I'm still getting used to > things like $_ and @ARGV!) The $1 contains the result of one of Perl's regex memory parentheses (page 110). As a backreference within the regex you would use \1 (for the 1st paren counting left to right) but outside the regex (for at least a while) you can then get this captured value via $1 (etc.). So my regex matches the dash and then captures a single character following (or fails). The "shift;" removes the first value from @ARGV if the regex matches (because this value then is an option and not a filename). There's a handy module that comes with Perk for such work: GetOpts (I think it's called) and it specializes (very easily) in handling command line options. > <snip> > while (@ARGV) { > my $file = ''; > > if ($ARGV[0] =~ /^-(.)$/) { > shift; # pull option off @ARGV > empty_trash($trash_path) if $1 eq 'e'; > restore_file([EMAIL PROTECTED]) if $1 eq 'r'; > ls_trash($trash_path) if $1 eq 'l'; > version() if $1 eq 'v'; > usage(); > > } else { > $file = shift; > $file =~ s/^--/-/; # allows dash to be escaped > move_to_trash($file); > } > } I hope that helps - there are better ways I'm sure to do things than mine - I really am only a few pages ahead of you :-) -K -- Kevin Pfeiffer International University Bremen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]