Arguments are in the list @ARGV. So if you want to set $oggdir to the first argument, or to /media/tmp if there is no first argument, you could do something like:
my $oggdir; if ($ARGV[0]) { $oggdir=$ARGV[0]; } else { $oggdir='/media/tmp'; }
A shorter and more idiomatic way to do the same thing is:
shift removes the first item from a list and returns it; in the main body of a program (outside of subs), it defaults to using @ARGV. So this is a little different than the above; it will remove the first argument from @ARGV. If shift returns an argument, $oggdir will be set to it; otherwise it will use the other half of the or, and set it to the default value.my $oggdir = shift || '/media/tmp';
If you want more complex argument processing, try using Getopt::Std or Getopt::Long.
In reply to Re: Using arguements and defaults
by sgifford
in thread Using arguements and defaults
by sock
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |