a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > Perl > 正文

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

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 久久视频一区二区 | 欧美不卡在线 | 欧美三级| 91久久精品一区二区二区 | 亚洲啊v在线 | 欧美精品一区二区在线观看 | 一级免费毛片 | 欧美日韩在线一区 | 91亚洲在线 | 在线免费av观看 | 日日躁夜夜操 | www.99re | 欧美日韩激情在线一区二区三区 | 国产99久久精品 | 国产成人在线视频 | 直接看av的网站 | 高清久久 | 成人免费视频视频在线观看 免费 | 国产女人和拘做受在线视频 | 亚洲精品久久久狠狠狠爱 | 久久久久av| 精品亚洲一区二区 | 久久精品一区二区三区四区 | 成人亚洲视频 | 99精品欧美一区二区三区综合在线 | 欧美一区二区三区在线看 | 国产精品二区一区二区aⅴ污介绍 | 免费看片国产 | 欧美高清在线 | 中文字幕一区二区三区四区 | 91秦先生艺校小琴 | 古典武侠第一页久久777 | 91色爱| 色爱av | 亚洲欧美另类久久久精品2019 | 97久久精品人人做人人爽50路 | 欧美激情在线观看 | 欧美日本久久 | 黄色影视在线 | 日韩午夜在线观看 | www久久久久久 |