ivaneeo's blog

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

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
          文檔選項
          將此頁作為電子郵件發(fā)送

          將此頁作為電子郵件發(fā)送

          未顯示需要 JavaScript 的文檔選項


          最新推薦

          Java 應(yīng)用開發(fā)源動力 - 下載免費軟件,快速啟動開發(fā)


          用傳統(tǒng)的 Unix 方式創(chuàng)建的簡單用戶界面

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

          使用 Getopt::Std 的命令行開關(guān)
          				
          						
          #!/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-殺雞就要用牛刀
          主站蜘蛛池模板: 昆山市| 延安市| 东源县| 台中市| 博客| 郑州市| 邻水| 仁布县| 肥乡县| 石门县| 永德县| 万山特区| 客服| 正镶白旗| 沛县| 房产| 蓝田县| 醴陵市| 萍乡市| 五大连池市| 北安市| 江达县| 团风县| 电白县| 盘锦市| 江孜县| 横峰县| 石嘴山市| 临沭县| 武山县| 威海市| 陵川县| 钟祥市| 新晃| 武川县| 宜章县| 西平县| 景东| 平山县| 肥乡县| 荃湾区|