位置: 编程技术 - 正文

Perl中的符号 ->;、=>; 和 :: 分别表示什么意思?(perl中的$1)

编辑:rootadmin

推荐整理分享Perl中的符号 ->;、=>; 和 :: 分别表示什么意思?(perl中的$1),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:perl中qw,perl常用函数,perl 制表符,perl-v,perl中qw,perl中qw,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:   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;

  两种方法的不同。

  但是,一般来说我们通常都使用这样的方法调用:

Perl中的符号 ->;、=>; 和 :: 分别表示什么意思?(perl中的$1)

  $top -> Widge-type;

  在perlref的手册页中有详尽的关于引用、解引用、和闭包的讨论,或者也可以在下面的网页上查看Perl5的信息页:

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

perl uc,lc,ucfirst,lcfirst大小写转换函数 大小写字母转换:函数uc(uppercase)将所有的小写字母转成大写;函数lc(lowercase)将所有的大写字母转成小写;Perl提供了四个内置的函数类,从而能够轻松

在Django框架中自定义模板过滤器的方法 自定义过滤器就是有一个或两个参数的Python函数:(输入)变量的值参数的值,可以是默认值或者完全留空例如,在过滤器{{var|foo:"bar"}}中,过滤器foo会被传

Perl图形化包管理工具PPM学习使用笔记 PPM(Programmer'sPackageManager)是ActivePerl自带的一个图形化管理工具,有了这个工具,要升级,更新,移除Perl的Package都非常方便。只需要输入ppm或者ppmgui就可

标签: perl中的$1

本文链接地址:https://www.jiuchutong.com/biancheng/368767.html 转载请保留说明!

上一篇:Perl中的特殊符号介绍(perl 特殊字符转义)

下一篇:perl uc,lc,ucfirst,lcfirst大小写转换函数

  • 净利润跟税后利润是二个概念吗
  • 往年有亏损本年没有亏损
  • 纳税调整项目包括哪些?请简单列举
  • 税控盘没有清卡,反写怎么办
  • 上个月的普票开错了怎么办
  • 律师异地立案费用
  • 增值税留抵抵欠税政策解读
  • 什么是进项加计扣除
  • 收据怎么粘贴在费用报销单上
  • 公司报销房租还能扣税吗
  • 废旧物资收购发票取消
  • 过桥过路费为什么这么贵
  • 变更了公司名称以前的发票还可以抵扣吗
  • 资产减值准备对股票的影响
  • 个人提供劳务给个人,不开票要缴税吗
  • 应交税费会计科目借贷方向
  • 公司向个人借入资金的风险
  • 个人去税务局能开什么类型的发票
  • 非居民企业出租不动产房产税
  • 车辆维修费
  • 独生子女费属于什么费用
  • 哪些项目可以享受简易征收
  • 个税申报中工资薪金是不是全年实际工资
  • 小规模企业所得税优惠政策最新2023
  • 一般企业的会计原始凭证有哪些类型
  • 华为鸿蒙os2.0发布
  • 缴纳人身意外保险凭证是什么
  • 客户预付的购货款是收入吗
  • 工业企业出售边角余料交的增值税税率是多少
  • 将现金存入银行,登记银行存款日记账的依据一般是
  • fatal error: opencv/cv.h: 没有那个文件或目录 错误;fatal error: opencv2/contrib/contrib.hpp: 没有那个文件或目录,opencv多版本
  • smart图形怎么单独设置动画
  • 增值税税收类型有哪些
  • vue+
  • 固定资产明细账登记
  • php获取并显示用户的用户名
  • 上市公司回购股票意味着什么
  • vue为什么监听不到对象内部属性
  • 残保金解决方案
  • 下载vue2
  • es6对象扩展运算符
  • 报关单份数
  • 应交税费中印花税是什么
  • 给境外公司代扣代缴税款
  • 材料已经入库但是没有发票怎么做账
  • 番茄开发票属于蔬菜吗?
  • 同一控制下收购溢价
  • 清算时存货是否要交税
  • 金税盘减免税款分录
  • 以固定资产投资取得长期股权投资
  • 税金及附加和营业税金及附加是一个科目吗
  • 如何判定企业库存现金
  • 固定资产的运输费和包装费计入
  • 以现金形式发工资违法吗
  • 抵扣旅客运输服务申报时填哪行
  • 资产负债表日后非调整事项应当在附注中披露
  • 什么差旅费
  • 车辆保险费计入现金流量表哪里
  • 施工单位月末都需要结转什么
  • mysql字符集设置命令
  • mysqlbinlog -vvv
  • windows自带软件有哪些
  • freebsd ntfs
  • win10怎么设置定时关机和开机
  • windows8文件夹怎么加密
  • 苹果mac安装win10系统
  • win7开机无法连接所有网络驱动器
  • android openconnect
  • js 加减
  • cocos2d安装教程
  • Vuforia ImageTarget Native版本编译
  • css如何实现
  • 安卓自定义app
  • jquery查找指定元素
  • 在python程序中变量名不能用
  • 国家税务总局通知公告
  • 电子税务局改版
  • 上海税务登记如何网上申请
  • 国际税务处岗位职责
  • 公寓土地增值税怎么算
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设