ivaneeo's blog

          自由的力量,自由的生活。

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(34)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          文檔選項

          未顯示需要 JavaScript 的文檔選項

          將此頁作為電子郵件發送

          將此頁作為電子郵件發送

          將此頁作為電子郵件發送

          將此頁作為電子郵件發送


          最新推薦

          Java 應用開發源動力 - 下載免費軟件,快速啟動開發


          用傳統的 Unix 方式創建的簡單用戶界面

          Unix 用戶非常熟悉基于文本的 UI 模型。設想有一個 Perl 程序,讓我們先看一下這個模型用于該程序的簡單實現。標準的 Getopt::Std 模塊簡化了命令行參數的解析。這個程序僅僅為了說明 Getopt::Std 模塊(沒有實際用途)。 請參閱本文后面的參考資料。

          使用 Getopt::Std 的命令行開關
          				
          						
          #!/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(); # the -h switch

          # 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
          {
          system('/bin/ls');
          }

          # print out the help and exit
          sub usage
          {
          print <<EOHIPPUS;
          first.pl [-l] [-h] [-f FILENAME]

          Lists the files in the current directory, using either /bin/ls or
          /bin/ls -l. The -f switch selects a different configuration file.
          The -h switch prints this help.
          EOHIPPUS
          exit;
          }
          posted on 2006-04-18 10:34 ivaneeo 閱讀(753) 評論(0)  編輯  收藏 所屬分類: perl-殺雞就要用牛刀
          主站蜘蛛池模板: 呈贡县| 开江县| 烟台市| 勐海县| 大渡口区| 富民县| 大名县| 沁源县| 博罗县| 酒泉市| 抚宁县| 通化市| 绍兴县| 灵璧县| 博罗县| 安溪县| 新泰市| 阳谷县| 崇明县| 嘉义县| 安西县| 沂水县| 富川| 东源县| 仙游县| 寻甸| 蓬安县| 汝州市| 琼结县| 阿鲁科尔沁旗| 招远市| 罗甸县| 临颍县| 措勤县| 通河县| 三门峡市| 苗栗县| 东辽县| 乐安县| 广水市| 北碚区|