Home | Mirror | Search | 杂文 | ITEYE 博客 | OSChina 博客 | 51CTO 博客

6.8. Parameter

6.8.1. Getopt::Std

#!/usr/bin/perl -w
use Getopt::Std;
Getopt::Std::getopts('a:b:c:de', \%options);
print "-a:$options{a} ";
print "-b:$options{b} ";
print "-c:$options{c} ";
print "-d:$options{d} ";
print "-e:$options{e} ";
			

6.8.2. Getopt::Long

#!/usr/bin/perl
use Getopt::Long;
Getopt::Long::GetOptions(
                 'page=i'     => $page,
                 'onoff!'     => $onoff,
                 'help'       => $wants_help,
                 'name=s'     => $name,
                 'number:i'   => $number);
if(defined($page)){
         print "page flag set to $page ";
}
if(defined($onoff)){
         print "onoff flag set to $onoff ";
}
if(defined($wants_help)){
         print "help flag set to $wants_help ";
}
if(defined($name)){
         print "name flag set to $name ";
}
if(defined($number)){
         print "number flag set to $number ";
}
			
comments powered by Disqus