Manish Uskaikar
Jul 14 2005, 03:33 PM
command line:
$perl man.pl manish
perl script
#!/usr/bin/perl;
($inputfile) = @ARGS;
Could anyone tell me how to accept the commandline parametes this does not seem to work.
Regards,
Manish U
Remo Sanges
Jul 14 2005, 03:42 PM
Manish Uskaikar wrote:
QUOTE |
command line:
$perl man.pl manish
perl script
#!/usr/bin/perl; ($inputfile) = @ARGS;
Could anyone tell me how to accept the commandline parametes this does not seem to work.
@ARGV and not @ARGS is an array |
so you have to use it by element.
In your case the name of the input file (manish)
seems to be the first argument.
So youshould use this code:
($inputfile) = @ARGV[0];
Remo Sanges
Jul 14 2005, 03:42 PM
Manish Uskaikar wrote:
QUOTE |
command line:
$perl man.pl manish
perl script
#!/usr/bin/perl; ($inputfile) = @ARGS;
Could anyone tell me how to accept the commandline parametes this does not seem to work.
@ARGV and not @ARGS is an array |
so you have to use it by element.
In your case the name of the input file (manish)
seems to be the first argument.
So youshould use this code:
($inputfile) = @ARGV[0];
HTH
Remo
Remo Sanges
Jul 14 2005, 03:46 PM
Remo Sanges wrote:
QUOTE |
Manish Uskaikar wrote:
command line:
$perl man.pl manish
perl script
#!/usr/bin/perl; ($inputfile) = @ARGS;
Could anyone tell me how to accept the commandline parametes this does not seem to work.
@ARGV and not @ARGS is an array so you have to use it by element. In your case the name of the input file (manish) seems to be the first argument.
So youshould use this code:
($inputfile) = @ARGV[0];
HTH
Remo
Sorry... |
Too hot here in Naples.... ;-)
The rigth code is
($inputfile) = $ARGV[0];
Remo
Todd W
Jul 14 2005, 04:17 PM
"Manish Uskaikar" <[Email Removed]> wrote in message
news:[Email Removed]...
command line:
$perl man.pl manish
perl script
#!/usr/bin/perl;
($inputfile) = @ARGS;
Could anyone tell me how to accept the commandline parametes this does not
seem to work.
for simple arguments this works great. If you want to parse complex command
line arguments, use Getopt::Long.This module comes with perl. Heres an
example:
my $opts = { };
GetOptions( $opts => qw/directory=s loglevel=s/);
my $missing = [ ];
foreach my $option ( qw/directory loglevel/ ) {
push( @{ $missing }, $option ) unless ( $opts->{ $option } );
}
usage( $missing ) if ( @{ $missing } );
sub usage {
my $args = shift; my $usage;
$usage = join("", map("missing required parameter: '$_'n", @{ $args }),
"n" );
$usage .= 'Usage: $ ' . $0 . ' \' . "n";
$usage .= ' --directory=/path/to/zip/files \' . "n";
$usage .= ' --loglevel=[DEBUG|INFO|WARN|ERROR|FATAL]' . "nn";
die( $usage );
}
Enjoy,
Todd W.
John Doe
Jul 14 2005, 04:28 PM
Manish Uskaikar am Donnerstag, 14. Juli 2005 18.21:
QUOTE |
command line: $perl man.pl manish
perl script: #!/usr/bin/perl; ($inputfile) = @ARGS;
Could anyone tell me how to accept the commandline parametes this does not seem to work.
|
please put the following lines into every script/module you write, since it
gives you error messages and hints about what could be/going wrong:
use strict;
use warnings;
joe
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.