麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Perl > 正文

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

2020-10-31 14:50:41
字體:
供稿:網(wǎng)友

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)。換句話說,它是調(diào)用由引用傳遞參數(shù)的子程序的方法(當(dāng)然,還有其它的作用)。正如我們上面所提到的,在調(diào)用Perl/Tk的函數(shù)的時候,大部分參數(shù)都是通過引用傳遞的。Perl中的‘->'功能就和它們在C或C++中一樣。(大部分原始的組件都是Tk中的Perl類的元素。)下面是一個簡單的解引用的例子:

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

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

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

  my($top) = MainWindow->new;

  和

  my($top) = new MainWindow;

  兩種方法的不同。

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

  $top -> Widge-type;

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

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

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

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

  $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');

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

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

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

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

  $a::b::c; # Perl 5中的標(biāo)量

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

  %a::b::c; # Perl 5中的關(guān)聯(lián)數(shù)組(或叫hash)

  &a::b::c; # Perl 5中的函數(shù)

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

  $main'foo; # Perl 4中的標(biāo)量$foo

  $main::foo; # Perl 5中的標(biāo)量$foo

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 午夜视频在线观看免费视频 | 做羞羞视频 | 91精品观看91久久久久久国产 | 黑人日比视频 | 亚洲一区在线免费视频 | 久在线观看福利视频69 | 337p粉嫩大胆噜噜噜亚瑟影院 | 性生活视频一级 | 中国免费一级毛片 | 久久久久久久久久久影视 | av手机免费在线观看 | 久久久久久亚洲国产精品 | 欧美亚洲另类在线 | 日韩视频高清 | 黄网站免费观看视频 | 欧美成人激情在线 | 成人在线视频在线观看 | 免费国产自久久久久三四区久久 | 欧美日韩亚洲不卡 | 一级做受大片免费视频 | 极品一级片| 快播av在线 | 国产精品久久久久久久久久10秀 | 亚洲操比视频 | 性高湖久久久久久久久aaaaa | 国产精品视频亚洲 | 久久久久久久久久久久久久国产 | 97人操 | 国产美女爽到喷白浆的 | 日日摸夜夜添夜夜添牛牛 | 欧美成人激情 | 素人视频免费观看 | 国内精品久久久久久2021浪潮 | 狠狠99| 毛片天天看 | 亚洲视频综合 | 99爱国产精品 | 久久成人国产精品入口 | chinese xvideos gay | 国产99精品 | 黄色av网站免费看 |