免费注册 查看新帖 |

Chinaunix

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

请帮忙解释下特殊的‘<>’ [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-06-27 17:02 |只看该作者 |倒序浏览
本帖最后由 soul20040103 于 2011-06-27 17:37 编辑

各位高手,
   能不能帮忙解释<> 的用法。
   在线等~
my @arr = ('abc ddd', 'xyz aaa');
while(<@arr>) {
  print $_, "\n";
}

论坛徽章:
0
2 [报告]
发表于 2011-06-27 18:12 |只看该作者
       If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name,
       typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed, and either a list of filenames or
       the next filename in the list is returned, depending on context.  This distinction is determined on syntactic grounds
       alone.  That means "<$x>" is always a readline() from an indirect handle, but "<$hash{key}>" is always a glob().  That's
       because $x is a simple scalar variable, but $hash{key} is not--it's a hash element.  Even "<$x >" (note the extra space)
       is treated as "glob("$x ")", not "readline($x)".

       One level of double-quote interpretation is done first, but you can't say "<$foo>" because that's an indirect filehandle
       as explained in the previous paragraph.  (In older versions of Perl, programmers would insert curly brackets to force
       interpretation as a filename glob: "<${foo}>".  These days, it's considered cleaner to call the internal function
       directly as "glob($foo)", which is probably the right way to have done it in the first place.)  For example:

           while (<*.c>) {
               chmod 0644, $_;
           }

       is roughly equivalent to:

           open(FOO, "echo *.c | tr -s ' \t\r\f' '\\012\\012\\012\\012'|");
           while (<FOO>) {
               chomp;
               chmod 0644, $_;
           }


相当于glob的作用。

论坛徽章:
0
3 [报告]
发表于 2011-06-27 18:34 |只看该作者
谢谢仙子!
不过。。。你贴的东西 我看明白了。。 是很像。。 不过不敢确定你说的对不对。
自己还有身边的朋友从来没那样写过。。。

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
4 [报告]
发表于 2011-06-27 21:41 |只看该作者
你不是在找高手吗?.....

高手(版主)在你“眼前”... ...啊你看不到....

论坛徽章:
0
5 [报告]
发表于 2011-06-28 10:08 |只看该作者

感觉那问题有点儿类似 孔乙己所谓的“回字四种写法”。。。
呵呵。很少人用吧。我是没用过。
罢了, 就那么理解。 再次谢过仙子。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP