Provided by: manpages-zh_1.5-1_all bug

NAME

       perlfaq7 - 綜合的問題 (2003/07/24 02:17:21)

DESCRIPTIONyz
       本節討論綜合的 Perl 語言問題,不適於在其他所有段落中討論的問題

       PerlBNF/yacc/RE$@%*n/?

       一種從 Perl呼叫編譯好的 C程式碼的方法。閱讀 perlxstut是-
       茼h了解擴充(extensions)的好方法。

       PerlC/OVH

       可以使用 Scalar::Util 模塊中的 tainted() 函數 (可從 CPAN 獲取,也包含在
       Perl 5.8.0 中)。參見 perlsec 中的 "Laundering and Detecting Tainted
       Data" 。

      O]H

       關於閉包的說明,請看 perlref 。

       閉包 (closure)是蚨踳T但又很難解釋的電腦科學名詞。在 Perl 裏-
       情A閉包是以匿名函數的形式來實現,具有持續參照位於該函數-
       S圍之外的文字式變數滲鄐O。這些外部的文字變數會神奇地保留它-
       怞b閉包函數最初定義時的 (深連結)。

       如果一茧{式語言容許函數遞回另一茖蝻爾 (像 Perl
       就是),閉包便具有意義。-
       n注意的是,有些語言雖提供匿名函數的功能,但卻無法正確處理閉包; Python
       這蚖y言便是一例。如果n想多了解閉包的話,建議你去找本功能性程式設-
       p的教科書來看。Scheme這蚖y言不僅支援閉包,更鼓勵多加使用。

       以下是茖憳洩熔ㄔ籵蝻漕蝻G

           sub add_function_generator {
             return sub { shift + shift };
           }

           $add_sub = add_function_generator();
           $sum = $add_sub->(4,5);                # $sum is 9 now.

       閉包用起來就像是 函數樣板,其中保留了一些可以在稍後再填入的空格。
       add_function_generator() 所遞回的匿名函數在技術上來講並不能算是一-
       茬洛],因為它沒有用到任何位在這茖蝻齷圍之外的文字變數。

       把上掖o茖狺l和下掖o make_adder()函數對照一下,下掖o-
       茖蝻珨憐^的匿名函數中使用了一-
       茈~部的文字變數。這種指名外部函數的作法需n由 Perl遞回一-
       蚞A當的閉包,因此那茪憒r變數在匿名函數產生之時的K永久地被鎖進閉
       包裏。

           sub make_adder {
               my $addpiece = shift;
               return sub { shift + $addpiece };
           }

           $f1 = make_adder(20);
           $f2 = make_adder(555);

       這樣一來 "&$f1($n)" 永遠會是 20加上你傳進去的 $n ,而 "&$f2($n)" 將
       永遠會是 555加上你傳進去的 $n。$addpiece 的|在閉包中保留下來。

       閉包在比較實際的場合中也常用得到,譬如當你想把一些程式碼傳入一茖蝻氶G

           my $line;
           timeout( 30, sub { $line = <STDIN> } );

       如果n執行的程式碼當初是以字串的形式傳入的話,即 '$line = <STDIN>'
       ,那麼 timeout() 這荌眺Q的函數在回到該函數被呼叫時所在的-
       S圍後便無法再擷取 $line 這茪憒r變數的F。

      OqAH

       變數自殺指的是 (暫時或是永久)地失去一蚥僂瘓。造成這茞{象的鴞]是做-
       S圍界定的 my() 和 local()和閉包或 foreach()回圈變數及函數參數相互影響
       所P。過去很容易偶爾丟失變量,現在就困難多了,可以試試這段代碼:

           my $f = "foo";
           sub T {
             while ($i++ < 3) { my $f = $f; $f .= "bar"; print $f, "\n" }
           }
           T;
           print "Finally $f\n";

       有三 "bar" 加進去的 $f 變數應該是一虓s的 $f (因為 "my $f" 在每-
       荋`環都應該創造一虓s的區域變數)。然而,實際上並非如此。這荅鞃帠抪s的
       Perl 版本中已被蚰 (在 5.004_05, 5.005_03 和 5.005_56 上測試過)。

      p/Function,y` FileHandle, Array,Hash,k Method,hF Regex}?

       除了正規表現式這荅S例外,你需n以傳參考漱閬▲禤像o些物件。參看
       perlsub 中的 "Pass by Reference",裏惘陸w對此問題的討論,以及 perlref
       裏惘酗犍峈爾穈T。

       參見下悸 ``Passing Regexes'',學習如何傳遞正則表達式。

       傳遞變量和函數
           一般的變數和函數是相當簡單的:只n傳一-
           茷向現存的匿名變數或函數的參考Y可:

               func( \$some_scalar );

               func( \@some_array  );
               func( [ 1 .. 10 ]   );

               func( \%some_hash   );
               func( { this => 10, that => 20 }   );

               func( \&some_func   );
               func( sub { $_[0] ** $_[1] }   );

       傳遞檔案句柄
           在 Perl5.6
           中,你可以用標量變量表示檔案句柄,並將它與其他標量同樣處理

                   open my $fh, $filename or die "Cannot open $filename! $!";
                   func( $fh );

                   sub func {
                           my $passed_fh = shift;

                           my $line = <$fh>;
                           }

           在 Perl5.6 之前,必須用 *FH 或 "\*FH" 語法。這叫做
           "typeglobs"--參見 perldata 中的 "Typeglobs and Filehandles" 和
           perlsub 中的 "Pass by Reference"。

       傳遞正則表達式
           n傳遞正則表達式,你需n使用足夠新的 Perl 發行,足以支持 "qr//"
           構造方式的版本,傳遞字符串,使用一荇滅繰妤`的
           eval,或者其他更聰明的辦法。

           這裏有一茼p何傳遞正則表達式字符串的例子,使用 "qr//":

               sub compare($$) {
                   my ($val1, $regex) = @_;
                   my $retval = $val1 =~ /$regex/;
                   return $retval;
               }
               $match = compare("old McDonald", qr/d.*D/i);

           注意 "qr//" 如何允許在後悼[上標誌。這-
           蚍狾’b編譯期被編譯,儘管它後來才執行。 "qr//"
           表示法雖然好用,但是直到 5.005
           發行中才引入。在那之前,你必須用不直觀的辦法。例如,如果沒有 "qr//"
           的話:

               sub compare($$) {
                   my ($val1, $regex) = @_;
                   my $retval = eval { $val1 =~ /$regex/ };
                   die if $@;
                   return $retval;
               }

               $match = compare("old McDonald", q/($?i)d.*D/);

           確保你沒有任何這樣的東西:

               return eval "\$val =~ /$regex/";   # WRONG

           否則別人會靠雙引號括起來的字串以及 eval 雙姜挭隍漸遢閬荌蔑蓬﹞J
           shell指令來作壞事。例如:

               $pattern_of_evil = 'danger ${ system("rm -rf * &") } danger';

               eval "\$string =~ /$pattern_of_evil/";

           想學非常非常聰明的方法的讀者可以參考 O'Reilly 出的 Mastering
           Regular Expressions這本書,作者是 Jeffrey Friedl。其中第 273隍
           Build_MatchMany_Function()特別的有趣。在 perlfaq2中可以找到有關本書
           的資料。

       傳遞方法
           n傳遞一蚢龠H方法給一茖蝻A可以這樣做:

               call_a_lot(10, $some_obj, "methname")
               sub call_a_lot {
                   my ($count, $widget, $trick) = @_;
                   for (my $i = 0; $i < $count; $i++) {
                       $widget->$trick();
                   }
               }

           或者,使用一茬洛]來包含這蚢龠H,它的方法調用及參數:

               my $whatnot =  sub { $some_obj->obfuscate(@args) };
               func($whatnot);
               sub func {
                   my $code = shift;
                   &$code();
               }

           也可以研究 UNIVERSAL 類別中的 can()方法 (附於標準 Perl 版本中)。

       How do I create a static variable?

       就像與 Perl相關的其他事情一樣,``條條大路通羅馬''
       (TMTOWTDI)。對其他語言來說叫做 ``靜態變數'' (static variable)的東西,在
       Perl裏悼i能是一-
       茖蝻p有的變數(只有該函數自己看得到,且在不同的呼叫間保持定),或是一-
       蚗仵蚳p有(file-private)變數(只有同一蚗仵蚺云漕蝻~看得到)。

       以下就是實作函數私有變數的程式:

           BEGIN {
               my $counter = 42;
               sub prev_counter { return --$counter }
               sub next_counter { return $counter++ }
           }

       prev_counter() 和 next_counter() 將會共用一茤騣s譯時初始化的私有變數
       $counter。

       n聲明一蚗仵蚳p有(file-private)變數,你仍然得使用
       my(),將它放在檔案開頭處最外圍。假設現在是在 Pax.pm 這蚗仵釱堙G

           package Pax;
           my $started = scalar(localtime(time()));

           sub begun { return $started }

       當用 "use Pax" 或 "require Pax" 載入此模組時,這-
       蚥僂N會被初始化。不過它不會被資源回收,像其他出了有效-
       S圍的變數那樣,因為 begun()函數n用到它,但是沒有其他函數能擷取它。這-
       蚥僂ㄞ鄍H $Pax::started 的形式來擷取,因為它所存在的-
       S圍與此包裹無關。它存在的S圍是這蚗仵蛂C可想見地,一蚗仵釱堨i以放好幾-
       茈]裹,而所有的包裹都擷取同一茖p有變數,但從另一-
       蚗仵蚺丑A即使是屬於同一茈]裹(package),也不能取得它的C

       參見 perlsub 中的 "Persistent Private Variables" 的細節.

       What's the difference between dynamic and lexical (static) scoping?
       Between local() and my()?

       local($x) 將全域變數 $x的噿存起來,並在此函數執行期間賦予一虓s A此-
       i以從此函數所呼叫的其他函數裏看見。這整-
       茖B驟是在執行期間完成的,所以才叫做動態S圍選取 (dynamic
       scoping)。local()影響的是全域變數,或者稱作包裹變數或動態變數。

       "my($x)" 會創造一茈u能在目前這茖蝻堿搊o見的新變數。這-
       茖B驟是在編譯期完成(compile-time),所以稱作文字式或是靜態-
       S圍選取。my()總是作用在私有變數,也稱作文字式變數或(不當地)稱作靜態(-
       S圍選取)變數。

       例如:

           sub visible {
               print "var has value $var\n";
           }

           sub dynamic {
               local $var = 'local';   # 為全局變量暫時賦
               visible();              # 調用 $var 變量
           }

           sub lexical {
               my $var = 'private';    # 新的私有變量 $var
               visible();              # (在 sub 作用域之外不可見)
           }

           $var = 'global';

           visible();                  # prints global
           dynamic();                  # prints local
           lexical();                  # prints global

       你可以發現在整蚢L程中 ``private''這蚧都印不出來。那是因為 $var的-
       u存在於lexical() 函數的區塊裏情A對它所呼叫的函數來說是看不到的。

       總結來說,local()不會產生你想像中的私有、區域變數。它只是將一蚍阞-
       瞻岸@茈域變數。如果你n的是私有的變數,那麼 my() 才是你n找的。

       參見 perlsub 中的 "Private Variables via my()" 以及 "Temporary Values
       via local()" 來獲取詳情

      bsbPWq@Aps@AqH

       如果你知道你所在的是一茈]裹(package)的話,你可以直接指名,就像寫
       $Some_Pack::var 這樣。注意 $::var 這蚍g法 並非表示目前此包裹 (package)
       內的動態變數 $var,而是指在 main包裹(package) 裏的那荂A就等價於
       $main::var 。

               use vars '$var';
               local $var = "global";
               my    $var = "lexical";

               print "lexical is $var\n";
               print "global  is $main::var\n";

       可選的,可以使用編譯器指令 our() 來在當前靜態作用域中引入動態變量

               require 5.006; # our() did not exist before 5.6
               use vars '$var';

               local $var = "global";
               my $var    = "lexical";

               print "lexical is $var\n";

               {
                 our $var;
                 print "global  is $var\n";
               }

      `sMLsPH

       在深連結中,匿名函數中所用到的文字式變數O以該函數產生時所在的-
       S圍為準。在淺連結中,這些變數O以函數被呼叫時所在的S圍為準,如果在這-
       S圍中恰巧有同名的變數,便使用這些當地變數的-
       CPerl總是使用文字式變數(就是以
       my()創造的)式的深連結。然而,動態變數(也稱作全域(global),區域(local),或包裹(package)變數)在功效上是淺連結。就把這當作是少用它-
       怐漸t一茞z由好 了。請參考 "什麼是閉包" 一節。

      麼

       local()會把 =號右邊以序列情境來對待。而 <FH> 這蚞\讀的 動作,就像
       Perl裏許多的函數以及運算子一樣,會自動分辨出自己被呼叫時所在的情境並且採取適當的作法。一般來說,scalar()函數可以幫點忙。這-
       茖蝻篕琱W對資料本-
       不會有任何作用(與一般所認為的相反),但是會告訴它所作用的函數-
       n以對待純量漱隤k來運算。如果那-
       茖蝻S有預先定義好碰到純量情境的行為,那麼它當然也幫不了你(例如 sort()
       函數)。

       然而,在以上這茖狺l (local...)中,只n省略括號便可強制使用標量情境:

           local($foo) = <FILE>;           # WRONG
           local($foo) = scalar(<FILE>);   # ok
           local $foo  = <FILE>;           # right

       其實在這茖狺l中,或許你該改用文字式變數 (lexical variables),不過會碰到
       的問題跟上惜@樣:

           my($foo) = <FILE>;  # WRONG
           my $foo  = <FILE>;  # right

      pwq@A@ kH

       為什麼n這麼做? :-)

       如果你n覆蓋掉某茪澈堥蝻A例如說 open(),那你得將其定義從另一蚍珩楖
       入。參考 perlsub 中的 Overriding Builtin Functions。在
       "Class::Template" 裏惜]有蚑d例。

       如果你n覆蓋掉一 Perl運算子,像是 "+" 或 "**", 那你該使用 "use
       overload" 這蚑s用,在 overload 中有記載。

       如果你n覆蓋父類別 (parent class)裏的方法呼叫 (method calls),請看
       perltoot 中的 Overridden Methods 。

       &fooM foo()P?

       當你用 &foo的方式呼叫一茖蝻氶A你等於讓這茖蝻^取你目前 @_裏悸-
       A同時也跳過鴢洸w義 (prototypes)不用。這表式此函數抓到的是你當時的
       @_, 而非一茠讀 @_!雖然嚴格講起來它也不能算是 bug (但是在 perlsub裏-
       惇O這麼說的)但在大部份情況下,這也算不上是荅S別功能。

       當你用 &foo()的方式呼叫你的函數時,你會得到一虓s的 @_,但是鴢洸w義
       仍然會被避開不用。

       在一般情況下,你該用 foo()的方式去呼叫函數。只有在編譯器已事先知道這-
       茖蝻漫w義時,括號才能省略,譬如當這茖蝻狾b的模組或包裹被 use
       (但如果是被 require則不行)時,或是透過先前提及或 use
       subs宣告等方法,讓編譯器先接觸到這-
       茖蝻漫w義。用這種呼叫方式,即使是當括號省掉時,你都會得到一荌晁銂
       @_,不會有任何不該出現的舊搵d在上情C

      p@yyH

       這荌暋D在 perlsyn 檔案裏有更詳盡的解釋。簡單來說,因為 Perl本-
       已提供了多種不同的條件測試方法可供使用 (數騆、字串比較、
       glob比較、正規表示式 對應、覆蓋比較,及其它),所以並沒有正式的 case敘-
       z語法。雖然自 perl1起這就一直是許多人期盼的一荈等堙A但因
       Larry無法決定怎樣才是呈現這功能的最好方法,因此還是將它略掉。

       從 Perl 5.8 開始,n使用 swtich 和 case,可以使用 Switch
       擴展,就是這樣:

               use Switch;

       此後就可以用 switch 和 case 了.  It is not as fast as it could be
       because it's not really part of the language (it's done using source
       filters) but it is available, and it's very flexible.

       But if one wants to use pure Perl, the general answer is to write a
       construct like this:

           for ($variable_to_test) {
               if    (/pat1/)  { }     # do something
               elsif (/pat2/)  { }     # do something else
               elsif (/pat3/)  { }     # do something else
               else            { }     # default
           }

       下掖o蚋眾瑼 switch範例以模式對應為基礎。我戔Nn做的是對儲存在
       $whatchamacallit裏悸滌悁疿 (reference)的類型進行多-
       垮囓顗漣P斷。【譯注:$whatchamacallit 函意為 $what_you_might_call_it】

           SWITCH: for (ref $whatchamacallit) {

               /^$/            && die "not a reference";

               /SCALAR/        && do {
                                       print_scalar($$ref);
                                       last SWITCH;
                               };

               /ARRAY/         && do {
                                       print_array(@$ref);
                                       last SWITCH;
                               };

               /HASH/          && do {
                                       print_hash(%$ref);
                                       last SWITCH;
                               };

               /CODE/          && do {
                                       warn "can't print function ref";
                                       last SWITCH;
                               };

               # DEFAULT

               warn "User defined type skipped";

           }

       See "perlsyn/"Basic BLOCKs and Switch Statements"" for many other
       examples in this style.

       Sometimes you should change the positions of the constant and the
       variable.  For example, let's say you wanted to test which of many
       answers you were given, but in a case-insensitive way that also allows
       abbreviations.  You can use the following technique if the strings all
       start with different characters or if you want to arrange the matches
       so that one takes precedence over another, as "SEND" has precedence
       over "STOP" here:

           chomp($answer = <>);
           if    ("SEND"  =~ /^\Q$answer/i) { print "Action is send\n"  }
           elsif ("STOP"  =~ /^\Q$answer/i) { print "Action is stop\n"  }
           elsif ("ABORT" =~ /^\Q$answer/i) { print "Action is abort\n" }
           elsif ("LIST"  =~ /^\Q$answer/i) { print "Action is list\n"  }
           elsif ("EDIT"  =~ /^\Q$answer/i) { print "Action is edit\n"  }

       A totally different approach is to create a hash of function
       references.

           my %commands = (
               "happy" => \&joy,
               "sad",  => \&sullen,
               "done"  => sub { die "See ya!" },
               "mad"   => \&angry,
           );

           print "How are you? ";
           chomp($string = <STDIN>);
           if ($commands{$string}) {
               $commands{$string}->();
           } else {
               print "No such command: $string\n";
           }

      pwqqAkXH

       在 perlsub 中的 "Autoloading" 和 perltoot 中的 "AUTOLOAD: Proxy
       Methods" 裏 提到的 AUTOLOAD 方法讓你能捕捉對於未定義函數與方法的呼叫。

       When it comes to undefined variables that would trigger a warning under
       "use warnings", you can promote the warning to an error.

               use warnings FATAL => qw(uninitialized);

      ]tbP@kH

       一些可能的-
       鴞]:你用的繼承給搞混了、你拼錯了該方法的名字,或是物件的類別錯誤。這些事在
       perltoot裏都有更詳盡的說明。同時你也可以用 "print ref($object)" 來找出
       $object 這茠咱颽O被歸到蚚別底下。

       另一茈i能的鴞]是你在 Perl還不知道這茈]裹 (package)存在之前便將某-
       蚚別名稱在間接式物件語法中使用 (例如 "find Guru
       "Samy"")。最好是在開始使用你的包裹前,先確定都已經先把它-
       怍w義好了,如果你用的是 use 而非
       require的話,這件事便會自動處理好。不然的話,確定你使用箭頭式語法
       (例如,"Guru->find("Samy")"))。在perlobj 裏措鴭顗咱顗滌O號有詳盡解釋。

       Make sure to read about creating modules in perlmod and the perils of
       indirect objects in "Method Invocation" in perlobj.

      pe]H

       如果只是一蚗H意的程式的話,你可以用下-
       悸漱隤k找出目前正被編譯的包裹為何:

           my $packname = __PACKAGE__;

       但如果是一茪隤k的話,而且印出的錯誤訊息中n包含呼叫此方法的物件
       (不見得就是把這茪隤k編譯進去的那茠咱)則:

           sub amethod {
               my $self  = shift;
               my $class = ref($self) || $self;
               warn "called me from a $class object";
           }

      p`j perlNXH

       用內嵌 POD格式的方法把程式碼變注解。將n注釋掉的塊包含在 POD 標記內,
       例如 "=for nobody" 和 "=cut" (標誌著 POD 塊的結束).

           # 這是程式

           =for nobody

           all of this stuff

           接下來此處所有的文字都會被忽略

           =cut

           # program continues

       The pod directives cannot go just anywhere.  You must put a pod
       directive where the parser is expecting a new statement, not just in
       the middle of an expression or some other arbitrary grammar production.

       See perlpod for more details.

       How do I clear a package?

       Use this code, provided by Mark-Jason Dominus:

           sub scrub_package {
               no strict 'refs';
               my $pack = shift;
               die "Shouldn't delete main package"
                   if $pack eq "" || $pack eq "main";
               my $stash = *{$pack . '::'}{HASH};
               my $name;
               foreach $name (keys %$stash) {
                   my $fullname = $pack . '::' . $name;
                   # Get rid of everything with that name.
                   undef $$fullname;
                   undef @$fullname;
                   undef %$fullname;
                   undef &$fullname;
                   undef *$fullname;
               }
           }

       Or, if you're using a recent release of Perl, you can just use the
       Symbol::delete_package() function instead.

       How can I use a variable as a variable name?

       Beginners often think they want to have a variable contain the name of
       a variable.

           $fred    = 23;
           $varname = "fred";
           ++$$varname;         # $fred now 24

       This works sometimes, but it is a very bad idea for two reasons.

       The first reason is that this technique only works on global variables.
       That means that if $fred is a lexical variable created with my() in the
       above example, the code wouldn't work at all: you'd accidentally access
       the global and skip right over the private lexical altogether.  Global
       variables are bad because they can easily collide accidentally and in
       general make for non-scalable and confusing code.

       Symbolic references are forbidden under the "use strict" pragma.  They
       are not true references and consequently are not reference counted or
       garbage collected.

       The other reason why using a variable to hold the name of another
       variable is a bad idea is that the question often stems from a lack of
       understanding of Perl data structures, particularly hashes.  By using
       symbolic references, you are just using the package's symbol-table hash
       (like %main::) instead of a user-defined hash.  The solution is to use
       your own hash or a real reference instead.

           $USER_VARS{"fred"} = 23;
           $varname = "fred";
           $USER_VARS{$varname}++;  # not $$varname++

       There we're using the %USER_VARS hash instead of symbolic references.
       Sometimes this comes up in reading strings from the user with variable
       references and wanting to expand them to the values of your perl
       program's variables.  This is also a bad idea because it conflates the
       program-addressable namespace and the user-addressable one.  Instead of
       reading a string and expanding it to the actual contents of your
       program's own variables:

           $str = 'this has a $fred and $barney in it';
           $str =~ s/(\$\w+)/$1/eeg;             # need double eval

       it would be better to keep a hash around like %USER_VARS and have
       variable references actually refer to entries in that hash:

           $str =~ s/\$(\w+)/$USER_VARS{$1}/g;   # no /e here at all

       That's faster, cleaner, and safer than the previous approach.  Of
       course, you don't need to use a dollar sign.  You could use your own
       scheme to make it less confusing, like bracketed percent symbols, etc.

           $str = 'this has a %fred% and %barney% in it';
           $str =~ s/%(\w+)%/$USER_VARS{$1}/g;   # no /e here at all

       Another reason that folks sometimes think they want a variable to
       contain the name of a variable is because they don't know how to build
       proper data structures using hashes.  For example, let's say they
       wanted two hashes in their program: %fred and %barney, and that they
       wanted to use another scalar variable to refer to those by name.

           $name = "fred";
           $$name{WIFE} = "wilma";     # set %fred

           $name = "barney";
           $$name{WIFE} = "betty";     # set %barney

       This is still a symbolic reference, and is still saddled with the
       problems enumerated above.  It would be far better to write:

           $folks{"fred"}{WIFE}   = "wilma";
           $folks{"barney"}{WIFE} = "betty";

       And just use a multilevel hash to start with.

       The only times that you absolutely must use symbolic references are
       when you really must refer to the symbol table.  This may be because
       it's something that can't take a real reference to, such as a format
       name.  Doing so may also be important for method calls, since these
       always go through the symbol table for resolution.

       In those cases, you would turn off "strict 'refs'" temporarily so you
       can play around with the symbol table.  For example:

           @colors = qw(red blue green yellow orange purple violet);
           for my $name (@colors) {
               no strict 'refs';  # renege for the block
               *$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
           }

       All those functions (red(), blue(), green(), etc.) appear to be
       separate, but the real code in the closure actually was compiled only
       once.

       So, sometimes you might want to use symbolic references to directly
       manipulate the symbol table.  This doesn't matter for formats, handles,
       and subroutines, because they are always global--you can't use my() on
       them.  For scalars, arrays, and hashes, though--and usually for
       subroutines-- you probably only want to use hard references.

       What does "bad interpreter" mean?

       The "bad interpreter" message comes from the shell, not perl.  The
       actual message may vary depending on your platform, shell, and locale
       settings.

       If you see "bad interpreter - no such file or directory", the first
       line in your perl script (the "shebang" line) does not contain the
       right path to perl (or any other program capable of running scripts).
       Sometimes this happens when you move the script from one machine to
       another and each machine has a different path to perl---/usr/bin/perl
       versus /usr/local/bin/perl for instance.

       If you see "bad interpreter: Permission denied", you need to make your
       script executable.

       In either case, you should still be able to run the scripts with perl
       explicitly:

               % perl script.pl

       If you get a message like "perl: command not found", perl is not in
       your PATH, which might also mean that the location of perl is not where
       you expect it so you need to adjust your shebang line.

AUTHOR AND COPYRIGHT

       Copyright (c) 1997-2002 Tom Christiansen and Nathan Torkington.  All
       rights reserved.

       This documentation is free; you can redistribute it and/or modify it
       under the same terms as Perl itself.

       Irrespective of its distribution, all code examples in this file are
       hereby placed into the public domain.  You are permitted and encouraged
       to use this code in your own programs for fun or for profit as you see
       fit.  A simple comment in the code giving credit would be courteous but
       is not required.

者
      AAuu@室