LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1449|回复: 6

关于Getopt::Std

[复制链接]
发表于 2003-12-13 22:32:34 | 显示全部楼层 |阅读模式
#!/usr/local/binSunOS/perl -w

use Getopt::Std;

getopt('abcd:ef:');
print "Switch a is on\n" if $opt_a;
print "Switch b is on \n" if $opt_b;
print "Switch c is on \n" if $opt_c;
print "Debug switch set to $opt_d\n" if $opt_d > 5;
print "Switch e is on\n" if $opt_e;
if ($opt_f) {
  print "Cannot locate file $opt_f\n" unless -e $opt_f;
}

for $I (1..5) {
  print "Value of I is $I\n" if $opt_d;
}

print "No (more) switches specified\n";


我想问一下这个关于Getopt:Std的例子中getopt('abcd:ef:');为什么有双冒号?有什么作用呢?
发表于 2003-12-13 22:46:06 | 显示全部楼层
发表于 2003-12-14 18:24:59 | 显示全部楼层
不能安装Getopt::Std

cpan> install Getopt::Std
CPAN: Storable loaded ok
Going to read /root/.cpan/Metadata
  Database was generated on Sat, 13 Dec 2003 10:47:43 GMT
Running install for module Getopt::Std
Running make for N/NW/NWCLARK/perl-5.8.2.tar.gz

The most recent version "1.04" of the module "Getopt::Std"
comes with the current version of perl (5.8.2).
I'll build that only if you ask for something like
    force install Getopt::Std
or
    install N/NW/NWCLARK/perl-5.8.2.tar.gz
Running make test
  Make had some problems, maybe interrupted? Won't test
  Has no own directory
Running make install
  Has no own directory
  Make had some problems, maybe interrupted? Won't install

cpan>

但好象能强制安装。。。
发表于 2003-12-14 18:35:48 | 显示全部楼层
这里还有个脚本。

#!/usr/bin/perl
use strict;
use Getopt::Std;

my %opts;
getopts("c:hv", %opts);

foreach(keys %opts)
{
   /c/ && print "welcome to ", $opts{$_} || "ChinaUnix", "!\n";
   /h/ && print "Usage : $0 -[hv] -[c msg] \n";
   /v/ && print "This is demo, version 0.001.001 built for $^O\n";
}
exit 0;
 楼主| 发表于 2003-12-15 06:50:23 | 显示全部楼层
怎样下在安装一个模块呢?
我在书上还没有看到这个
发表于 2003-12-15 13:58:21 | 显示全部楼层
最初由 the_threeeyes 发表
怎样下在安装一个模块呢?
我在书上还没有看到这个


置顶有一贴是专门说模块的。。
发表于 2003-12-15 14:01:55 | 显示全部楼层
一般安裝perl 的模块很簡單 perl Makefile.PL PREFIX=/usr;make;make install 便可
不過樓主這個模块一般都有的不用四處找
可參考這個
http://www.cpan.org/modules/00modlist.long.html#ID1_ModuleListi
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表