get the arguements of the scripts and then you can parse the arguements.
this is the same with
import optparse.
- #!/usr/bin/perl -w
-
#
-
use strict;
-
-
use Getopt::Std;
-
sub init{
-
-
my %opt;
-
my $opt_string = 'hd:f:p:';
-
getopts("$opt_string", \%opt);
-
-
usage() if ( $opt{h} or not %opt);
-
}
-
sub usage{
-
print "useage of this file\n";
-
}
-
init();
the arguements will store in %opt. my $arg1 = $opt{d}.....
the : in $opt_string indicate that a value will follow the option. if no : follow the option, e.g. h, this indicate that no value should follow this arguement.
The getopts() function is similar, but you should pass to it the list of all
switches to be recognized. If unspecified switches are found on the
command-line, the user will be warned that an unknown option was given.
The getopts() function returns true unless an invalid option was found.so you can use
- getopts("$opt_string", \%opt) or usage();
to give out the usage.
阅读(669) | 评论(0) | 转发(0) |