Getopt::Std模块简单实例
来源:互联网 发布:开淘宝代理货源怎么找 编辑:程序博客网 时间:2024/05/22 10:26
#!/usr/bin/perl -w
use strict; # always use strict, it's a good habit
use Getopt::Std; # see "perldoc Getopt::Std"
my %options;
getopts('f:hl', /%options); # read the options with getopts
# uncomment the following two lines to see what the options hash contains
#use Data::Dumper;
#print Dumper /%options;
$options{h} && usage(1); # the -h switch, with exit option
# use the -f switch, if it's given, or use a default configuration filename
my $config_file = $options{f} || 'first.conf';
print "Configuration file is $config_file/n";
# check for the -l switch
if ($options{l})
{
system('/bin/ls -l');
}
else
{
my $input; # a variable to hold user input
do {
print "Type 'help' for help, or 'quit' to quit/n-> ";
$input = <>;
print "You entered $input/n"; # let the user know what we got
# note that 'listlong' matches /list/, so listlong has to come first
# also, the i switch is used so upper/lower case makes no difference
if ($input =~ /listlong/i)
{
system('/bin/ls -l');
}
elsif ($input =~ /list/i)
{
system('/bin/ls');
}
elsif ($input =~ /help/i)
{
usage();
}
elsif ($input =~ /quit/i)
{
exit;
}
}
while (1); # only 'quit' or ^C can exit the loop
}
exit; # implicit exit here anyway
# print out the help and exit
sub usage
{
my $exit = shift @_ || 0; # don't exit unless explicitly told so
print <<EOHIPPUS;
first.pl [-l] [-h] [-f FILENAME]
The -l switch lists the files in the current directory, using /bin/ls -l.
The -f switch selects a different configuration file. The -h
switch prints this help. Without the -l or -h arguments, will show
a command prompt.
Commands you can use at the prompt:
list: list the files in the current directory
listlong: list the files in the current directory in long format
help: print out this help
quit: quit the program
EOHIPPUS
exit if $exit;
}
- Getopt::Std模块简单实例
- Perl 模块 Getopt::Std 和 Getopt::Long
- Getopt::Std模块的使用
- Getopt::Std模块的使用:
- perl模块Getopt::Std用法及实例-从命令行读取参数模块
- perl模块Getopt::Std用法及实例-从命令行读取参数模块
- perl模块 Getopt::Std模块的使用
- Getopt::Std
- getopt模块
- getopt 模块
- getopt实例
- NodeJs 模块简单实例
- Getopt::Long 模块zz
- python中 getopt 模块
- [python] getopt模块
- python中的getopt模块
- Python getopt模块
- Python之getopt模块
- 项目中成功的运用proxool连接池
- 很好的网络监控软件
- Windows CE内存管理机制 -转
- 对 Windows 窗体控件进行线程安全调用
- C++经典教材
- Getopt::Std模块简单实例
- C#组播知识
- Web Service & Client
- vs2005 中的多线程(c#),可带参数-转
- QClub北京:OpenSocial的规范、实践与展望
- Web挖掘技术
- 各个网络端口的入侵方法
- WebSphere5.1下发布XFire的问题解决
- GridView编辑状态時取值,RowUpdating在更新前取編輯框的值進行判斷