in reply to Getting args

Take a look at @ARGV. It holds all your command line arguments, split by whitespace.

Update: DOH! daveorg beat me to it, so I might as well add some other useful tidbits:

• Number of arguments passed: scalar @ARGV
• Program name: $0
• If all your arguments are filenames and you want to read them all in line by line, you can use <>. That's kinda neat sometimes, if you can trust your input!

Camel 3, p. 659

Replies are listed 'Best First'.
Re: Re: Getting args
by willa (Acolyte) on Dec 10, 2001 at 22:53 UTC
    How do I pattern-match a variable with the first one?
    if ($var =~ m/@ARGV[1]/) { ... }
    ???
      You were close.
      if ($var =~ /$ARGV[0]/) { ... }

      A more exact match:
      if ($var =~ /^$ARGV[0]$/) { ... }

      Updated: $ARGV[1] is the SECOND argument. $ARGV[0] is the first one.