| Refresh | Home EGTry.com

parse command line options


example to use Getopt::Std

use Getopt::Std;
use strict;

my %opts;
getopts("pf:t:", \%opts);

foreach my $key (keys %opts) {
  my $value=$opts{$key};
  print "$key=>$value\n";
}

print "\n\@ARGV: ", join(",", @ARGV), "\n";


command line options example:
perl getopt.pl -p -f input.txt -t "this is a test" arg1 arg2 more

output

p=>1
f=>input.txt
t=>this is a test

@ARGV: arg1,arg2,more