最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Perl中的符號 ->;、=>; 和 :: 分別表示什么意思?

 更新時間:2017年10月09日 14:54:05   投稿:mdxy-dxy  
這篇文章主要介紹了Perl中的符號 ->;、=>; 和 :: 分別表示什么意思,需要的朋友可以參考下

What do the ->, => and :: symbols mean?

  The -> is the "infix dereference operator". In other words it is the means by which one calls a sub with a pass by reference (among other things you can do with ->). As stated above most things in calls to perl/Tk routines are passed by reference. The -> is used in perl just as in C or C++. (Most of the widget primitives are elements of the Tk:: "perl class".) A simple example of dereferencing would be: $x = { def => bar }; # $x is a reference to an anon. hash print $x->{def},"/n"; # prints ``bar''

  Note that in the case of calling perl/Tk subs there may be more than one way to call by reference. Compare my($top) = MainWindow->new;

  with my($top) = new MainWindow;

  But in general you will be making extensive use of calls like: $top -> Widge-type;

  There is a clear and succint discussion of references, dereferences, and even closures in man perlref(1) or see the perl 5 info page at: http://www.metronet.com/perlinfo/perl5.html

  The use of the => operator is quite common in perl/Tk scripts. Quoting from man perlop(1):

  The => digraph is simply a synonym for the comma operator. It's useful for documenting arguments that come in pairs.

  You could say that => is used for aesthetic or organizational reasons. Note in the following how hard it is to keep track of whether or not every -option has an argument: $query -> Button(-in,/$reply,-side,'left',-padx,2m,-pady, 2m,-ipadx,2m,-ipady,1m)->pack(-side,'bottom');

  As opposed to: $query ->Button( -in => /$reply, -side => 'left', -padx => 2m, -pady => 2m, -ipadx => 2m, -ipady => 1m )->pack(-side => 'bottom');

  By the way if you wanted the numeric "greater than or equal" you would use >= not =>.

  While the :: symbol can be thought of as similar to the period in a C struct, it is much more akin to the :: class scope operator in C++: a.b.c; /* something in C */ a::b::c(); // function in C++ $a::b::c; # a scalar in Perl 5 @a::b::c; # a list in Perl 5 %a::b::c; # an associative array or "hash" in Perl 5 &a::b::c; # a function in Perl 5

  It is also analogous to the single forward quotation mark in perl 4: $main'foo; # a $foo scalar in perl 4 $main::foo; # a $foo scalar in Perl 5

  For backward compatibility perl 5 allows you to refer to $main'foo but $main::foo is recommended.

  譯文:

  符號->,=>和::分別表示什么意思?

  ‘- >'符號是“插入式解引用操作符”(infix dereference operator)。換句話說,它是調用由引用傳遞參數的子程序的方法(當然,還有其它的作用)。正如我們上面所提到的,在調用Perl/Tk的函數的時候,大部分參數都是通過引用傳遞的。Perl中的‘->'功能就和它們在C或C++中一樣。(大部分原始的組件都是Tk中的Perl類的元素。)下面是一個簡單的解引用的例子:

  $x = { def => bar }; # $x是指向一個匿名hash的引用

  print $x->{def},"/n"; # 輸出``bar''

  注意,在調用Perl/Tk的子程序時有多種不同的方法進行引用。我們可以比較一下:

  my($top) = MainWindow->new;

  和

  my($top) = new MainWindow;

  兩種方法的不同。

  但是,一般來說我們通常都使用這樣的方法調用:

  $top -> Widge-type;

  在perlref的手冊頁中有詳盡的關于引用、解引用、和閉包的討論,或者也可以在下面的網頁上查看Perl5的信息頁:

  http://www.metronet.com/perlinfo/perl5.html

  在Perl/Tk的腳本中‘=>'操作符時很常見的。perlop手冊頁中說:關系操作符=>只是逗號操作符的替代物,它在顯示成對的參數時非常有用。

  你可以認為=>只是為了程序的美觀和易維護而被使用的。請看,在下面的例子中,要想監(jiān)測是否每個選項都有對應的值,是多么的困難:

  $query -> Button(-in,/$reply,-side,'left',-padx,2m,-pady,

  2m,-ipadx,2m,-ipady,1m)->pack(-side,'bottom');

  而下面的這個則相反:

  $query ->Button( -in => /$reply,

  -side => 'left',

  -padx => 2m,

  -pady => 2m,

  -ipadx => 2m,

  -ipady => 1m

  )->pack(-side => 'bottom');

  順便說一下,如果你需要用數字“大于等于”的符號,你應該用“>=”而不是“=>”。

  “::”符號可以認為是與C語言中的“.”相似的,而它更像C++中的::類范圍操作符。

  a.b.c; /* C語言中的 */

  a::b::c(); // C++ 中的函數

  $a::b::c; # Perl 5中的標量

  @a::b::c; # Perl 5中的列表

  %a::b::c; # Perl 5中的關聯數組(或叫hash)

  &a::b::c; # Perl 5中的函數

  另外,Perl4中的單撇號也具有相同的功能:

  $main'foo; # Perl 4中的標量$foo

  $main::foo; # Perl 5中的標量$foo

  出于向后兼容的考慮,Perl5也運行使用$main'foo,但是仍推薦使用$main::foo。

相關文章

  • 如何使用perl的Tie::File?模塊刪除文件固定行

    如何使用perl的Tie::File?模塊刪除文件固定行

    使用perl的Tie::File?模塊刪除文件固定行,?這里的處理主要利用了perl的Tie::File?模塊把數組和文件綁定,然后就可以使用perl的splice函數操作數組,從而達到操作文件的目的,對perl刪除文件固定行感興趣的朋友跟隨小編一起看看吧
    2023-12-12
  • perl用變量做句柄介紹

    perl用變量做句柄介紹

    在perl代碼中,open 有一個特殊的地方,就是如果你給它一個未定義(這是為什么用hash的原因)的變量做間接文件句柄,那么 Perl 會自動為你定義那個變量,也就是自動把它激活,使它包含一個合適的文件句柄引用
    2013-02-02
  • Perl學習教程之單行命令詳解

    Perl學習教程之單行命令詳解

    這篇文章主要給大家介紹了關于Perl學習教程之單行命令的相關資料,文中給出了詳細的示例代碼供大家參考學習,對大家學習或者使用perl具有一定的參考學習價值,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-09-09
  • Perl AnyEvent中的watcher實例

    Perl AnyEvent中的watcher實例

    這篇文章主要介紹了Perl AnyEvent中的watcher實例,關于AnyEvent請參閱的更多介紹請參閱文中的相關鏈接,需要的朋友可以參考下
    2014-09-09
  • cpan安裝Net::SSH::Perl中遇到的一些問題

    cpan安裝Net::SSH::Perl中遇到的一些問題

    cpan安裝Net::SSH::Perl中遇到的一些問題,需要的朋友可以參考下
    2013-02-02
  • perl的格式化(Format)報表輸出實現代碼

    perl的格式化(Format)報表輸出實現代碼

    perl有最好的文本數據處理能力.這是大家都知道的.在perl本身有一個別的軟件沒有的小功能,就是Perl格式.它相當于簡單的命令行報表和圖表輸出
    2013-01-01
  • perl use 命令中指定路徑的方法

    perl use 命令中指定路徑的方法

    如果要對使用的lib指定路徑,可以使用下面的語法
    2013-02-02
  • Perl刪除前導和拖尾空白(刪除左右空格、空白字符)

    Perl刪除前導和拖尾空白(刪除左右空格、空白字符)

    這篇文章主要介紹了Perl刪除前導和拖尾空白(刪除左右空格、空白字符),本文給出了多個方法實現解決這個需求,需要的朋友可以參考下
    2015-06-06
  • Perl中的子程序學習筆記

    Perl中的子程序學習筆記

    這篇文章主要介紹了Perl中的子程序學習筆記,本文講解了子程序的定義、調用、返回值、局部變量、子程序參數傳遞等內容,需要的朋友可以參考下
    2015-02-02
  • perl哈希的一個實例分析

    perl哈希的一個實例分析

    上一篇文章介紹了hash的入門教程,這篇文章為大家提供一個實例,方便大家深入學習
    2013-02-02

最新評論

宁蒗| 桦甸市| 宜州市| 交城县| 兴安县| 沙坪坝区| 台中县| 密山市| 翁牛特旗| 宁海县| 建宁县| 桐柏县| 土默特右旗| 临城县| 杭锦后旗| 朔州市| 泽库县| 长顺县| 嘉鱼县| 泊头市| 右玉县| 万源市| 嘉定区| 瑞丽市| 贵溪市| 青河县| 靖边县| 锡林郭勒盟| 江孜县| 望奎县| 康定县| 股票| 乐安县| 烟台市| 来宾市| 台中县| 抚顺市| 池州市| 恩平市| 天水市| 如东县|