免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1745 | 回复: 5
打印 上一主题 下一主题

菜鸟求教,关于->和=> [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-14 12:23 |只看该作者 |倒序浏览
刚刚接触perl
不了解-> 和=>,实在找不到合适的文档

请请教下各位大虾,这两个符号的作用、用法

论坛徽章:
0
2 [报告]
发表于 2009-09-14 12:35 |只看该作者
有一节专门讲操作符:http://perldoc.perl.org/perlop.html
The Arrow Operator

"-> " is an infix dereference operator, just as it is in C and C++. If the right side is either a [...] , {...} , or a (...) subscript, then the left side must be either a hard or symbolic reference to an array, a hash, or a subroutine respectively. (Or technically speaking, a location capable of holding a hard reference, if it's an array or hash reference being used for assignment.) See perlreftut and perlref.

Otherwise, the right side is a method name or a simple scalar variable containing either the method name or a subroutine reference, and the left side must be either an object (a blessed reference) or a class name (that is, a package name). See perlobj.



The =>  operator is a synonym for the comma except that it causes its left operand to be interpreted as a string if it begins with a letter or underscore and is composed only of letters, digits and underscores. This includes operands that might otherwise be interpreted as operators, constants, single number v-strings or function calls. If in doubt about this behaviour, the left operand can be quoted explicitly.

Otherwise, the => operator behaves exactly as the comma operator or list argument separator, according to context.

[ 本帖最后由 Perl_Er 于 2009-9-14 12:36 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2009-09-14 13:08 |只看该作者

回复 #2 Perl_Er 的帖子

Thanks

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2009-09-14 13:25 |只看该作者
先看小骆驼。
不系统地学,这方法就有问题。

论坛徽章:
0
5 [报告]
发表于 2009-09-14 13:30 |只看该作者
->我只知道用在数组,hash引用。


=>我知道用在定义hash对应关系时用的%hash = (                     
                     "DLT8000"     => "28",
                     "SuperDLT1"   => "41",
                     "SDLT320"     => "42",
                     "SONY-AIT2"   => "14",
                     "SONY-AIT3"   => "15",
                     "SONY-AIT4"   => "16",
                     )

论坛徽章:
0
6 [报告]
发表于 2009-09-14 13:55 |只看该作者
原帖由 dahe_1984 于 2009-9-14 13:30 发表
->我只知道用在数组,hash引用。


=>我知道用在定义hash对应关系时用的%hash = (                     
                     "DLT8000"     => "28",
                     "SuperDLT1"   => "41",
    ...

->面向对象里面方法的调用也有.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP