濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Perl中的符號(hào) -;;、=;; 和 :: 分別表示什么意思?

Perl中的符號(hào) -;;、=;; 和 :: 分別表示什么意思?

熱門(mén)標(biāo)簽:熱門(mén)電銷機(jī)器人 電話機(jī)器人哪里有賣 外呼電信系統(tǒng) 河南虛擬外呼系統(tǒng)公司 惠州龍門(mén)400電話要怎么申請(qǐng) 智能機(jī)器人電銷神器 上海企業(yè)外呼系統(tǒng) 萬(wàn)利達(dá)百貨商場(chǎng)地圖標(biāo)注 okcc外呼系統(tǒng)怎么調(diào)速度

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.

  譯文:

  符號(hào)->,=>和::分別表示什么意思?

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

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

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

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

  my($top) = MainWindow->new;

  和

  my($top) = new MainWindow;

  兩種方法的不同。

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

  $top -> Widge-type;

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

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

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

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

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

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

  而下面的這個(gè)則相反:

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

  -side => 'left',

  -padx => 2m,

  -pady => 2m,

  -ipadx => 2m,

  -ipady => 1m

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

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

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

  a.b.c; /* C語(yǔ)言中的 */

  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中的單撇號(hào)也具有相同的功能:

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

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

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

您可能感興趣的文章:
  • Perl5和Perl6對(duì)比使用Sigils的差別
  • Perl6中的垃圾收集
  • 強(qiáng)大的Perl正則表達(dá)式實(shí)例詳解
  • Perl中常見(jiàn)符號(hào)與操作
  • Perl學(xué)習(xí)教程之單行命令詳解
  • Perl時(shí)間處理函數(shù)用法介紹
  • Perl字符串處理函數(shù)大全
  • 詳解linux下批量替換文件內(nèi)容的三種方法(perl,sed,shell)
  • Perl與JS的對(duì)比分析(數(shù)組、哈希)
  • 使用Perl生成隨機(jī)密碼
  • ASP.NET中HyperLink超鏈接控件的使用方法
  • 將Perl5代碼遷移到Perl6上的解決方案

標(biāo)簽:周口 秦皇島 百色 周口 綿陽(yáng) 合肥 淮安 綏化

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Perl中的符號(hào) -;;、=;; 和 :: 分別表示什么意思?》,本文關(guān)鍵詞  Perl,中的,符號(hào),和,分別,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Perl中的符號(hào) -;;、=;; 和 :: 分別表示什么意思?》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Perl中的符號(hào) -;;、=;; 和 :: 分別表示什么意思?的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    尉犁县| 垦利县| 南安市| 城市| 皮山县| 千阳县| 大英县| 长沙县| 郧西县| 四会市| 安阳市| 集贤县| 兴山县| 霞浦县| 建始县| 武川县| 建阳市| 甘肃省| 乳源| 航空| 西丰县| 咸宁市| 大冶市| 枣阳市| 罗田县| 曲阜市| 九龙坡区| 甘泉县| 甘谷县| 镇巴县| 历史| 田阳县| 晋城| 通江县| 泰宁县| 河源市| 孝感市| 平乡县| 虎林市| 洪泽县| 呼和浩特市|