;、=>; 和 :: 分別表示什么意思,需要的朋友可以參考下">

一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - perl - Perl中的符號 ->;、=>; 和 :: 分別表示什么意思?

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

2020-06-24 10:13Perl教程網 perl

這篇文章主要介紹了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手冊頁中說:關系操作符=>只是逗號操作符的替代物,它在顯示成對的參數時非常有用。

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

  $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。

延伸 · 閱讀

精彩推薦
  • perlperl常見問題集合之二

    perl常見問題集合之二

    哪些平臺上有 Perl?要到哪里去找? Perl的標準發行版(由 perl 發展小組負責維護)僅以原始碼形式發行。您可在 http: //www.perl.com/CPAN/src/latest.tar.gz處取得。這個檔...

    腳本之家2102020-05-29
  • perlperl命令行參數內建數組@ARGV淺析

    perl命令行參數內建數組@ARGV淺析

    這篇文章主要介紹了perl命令行參數內建數組@ARGV淺析,本文重點在于講解@ARGV的用法,并通過實例來說明,需要的朋友可以參考下 ...

    perl教程網6162020-06-18
  • perlperl pop push shift unshift實例介紹

    perl pop push shift unshift實例介紹

    perl的pop跟push操作數組的最右邊,shift跟unshift操作數組的最左邊 ...

    腳本之家4612020-06-10
  • perlperl use vars pragma使用技巧

    perl use vars pragma使用技巧

    perl 中的vars是perl中的一個pragma(預編譯指示符),專門用來預定義全局變量,這些預定義后的全局變量在qw()列表中,在整個引用perl文件中皆可使用,即便使...

    perl教程網6812020-06-16
  • perlPerl List::Util模塊使用實例

    Perl List::Util模塊使用實例

    這篇文章主要介紹了Perl List::Util模塊使用實例,本文給出掃描符合條件的某個列表并取出第一個符合條件的、求1到1000之間的和 、求一組數字的最大值與最小...

    腳本之家4712020-06-22
  • perlPerl使用nginx FastCGI環境做WEB開發實例

    Perl使用nginx FastCGI環境做WEB開發實例

    這篇文章主要介紹了Perl使用nginx FastCGI環境做WEB開發實例,實現了路由系統和模板系統,需要的朋友可以參考下...

    Perl教程網2412020-06-18
  • perlPerl的經典用法分享

    Perl的經典用法分享

    Perl的經典用法分享,學習perl的朋友可以參考下 ...

    腳本之家6562020-06-06
  • perlPerl從文件中讀取字符串的兩種實現方法

    Perl從文件中讀取字符串的兩種實現方法

    有時候我們需要從文件中讀取字符串,這里簡單介紹下, 需要的朋友可以參考下 ...

    腳本之家6252020-06-08
主站蜘蛛池模板: 校园春色自拍偷拍 | 白发在线视频播放观看免费 | 色老板在线 | 吉川爱美与黑人解禁 | 性欧美sexovideotv | 国产精品亚欧美一区二区三区 | 成人免费福利网站在线看 | 好湿好滑好硬好爽好深视频 | 国产综合久久久久 | 强女明星系列小说 | 亚洲欧美视频在线播放 | 午夜在线观看免费完整直播网页 | 国产亚洲精品一区二区在线观看 | 成人福利在线 | 幻女free性俄罗斯第一次摘花 | 亚洲精品视频在线 | 门房秦大爷最新章节阅读 | 俄罗斯烧性春三级k8播放 | 欧美特黄三级在线观看 | 视频一区久久 | 天堂a免费视频在线观看 | 成年人视频在线免费看 | 日本高清视频在线的 | 亚洲国产成人久久99精品 | 91桃色视频在线观看 | 黄动漫软件车车好快的车车 | 色综合久久综精品 | 91真人毛片一级在线播放 | 国产裸舞福利资源在线视频 | 欧美腐剧mm在线观看 | 毛片区 | 国产精品视频免费一区二区三区 | 国产亚洲精品精品国产亚洲综合 | 久久免费资源福利资源站 | 日产乱码卡1卡2卡三免费 | 手机能看的黄色网站 | 日本一区二区视频免费播放 | 免费深夜福利 | 国产成人8x视频一区二区 | 国产视频一二三区 | 亚洲欧洲综合 |