Help - Search - Member List - Calendar
Full Version: how to use command line parameters
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Manish Uskaikar
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
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
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
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
"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
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


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.