perl - Optionally passing command line arguments? -
i need optionally take command line argument user who's executing script. (i prefer not utilize getoptions()
).
i have 2 variables,
my ($port_name, $report); $port_name = $argv[0]; $report = $argv[1]; if (defined $port_name){ .... } if (defined $report){ .... }
if $report
flag not given command line argument not wish run sec if-block. how can done without perl giving me error?
thanks helping.
your code should work expected.....
hi[root@matthewharris cpanel]# perl blah.pl 1 hi[root@matthewharris cpanel]# perl blah.pl 1 2 hino[root@matthewharris cpanel]# [root@matthewharris cpanel]# cat blah.pl #!/usr/bin/perl utilize strict; utilize warnings; ( $port, $report ) = @argv; if ( $port ) { print 'hi'; } if ( $report ) { print 'no'; }
perl
No comments:
Post a Comment