"Bob Bondi" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> My question is: how can I pass arguments to a script from the command
line?
> The script at the tail of this message is what I thought would print the 2
> arguments I passed into the script, yet the output for this snippet is:
> Here ya go:
> Here ya go:
> Count is: 0
> Not enough arguments to get started
>
> #\perl\bin
>
> use strict; # use strict! It will save you many headaches
> use File::Basename;
> use Carp;
>
> my $count = @_;
> print "Here ya go: $_[0]\n";
> print "Here ya go: $_[1]\n";
> print "Count is: $count\n";
> carp "Not enough arguments to get started" unless $count > 0;
>
Bob,
Try this:
####################
#!\perl\bin # Do you want a shebang?
use strict; # use strict! It will save you many headaches
use File::Basename; # Do you need this module?
use Carp;
my $count = $#ARGV + 1; # Index of last item in list + 1.
print "Here ya go: $ARGV[0]\n"; # 1st command line argument.
print "Here ya go: $ARGV[1]\n"; # 2nd command line argument.
print "Count is: $count\n"; # Number of arguments.
carp "Not enough arguments to get started" unless $count > 0;
####################
@ARGV stores command line arguments.
For more sophisticated command line support, look at the GetOpt modules.
HTH,
Martin
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]