免费注册 查看新帖 |

Chinaunix

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

为什么我的机器就不能运行出正确的结果来,郁闷! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-11-19 16:52 |只看该作者 |倒序浏览
#!/usr/bin/perl
chomp(@lines = <STDIN>);
@line = sort @lines;

print @line;


#!/usr/bin/perl
chomp(@lines = <STDIN>);
@line = reverse @lines;

print @line;

print reverse <STDIN>;

为什么输入结果跟输入结果一样呢?郁闷啊

论坛徽章:
0
2 [报告]
发表于 2012-11-19 16:59 |只看该作者
都怪我,中文没有学好。。。

论坛徽章:
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
3 [报告]
发表于 2012-11-19 17:02 |只看该作者
回复 1# stesting


$ perldoc -f reverse
       reverse LIST
               In list context, returns a list value consisting of the
               elements of LIST in the opposite order.  In scalar context,
               concatenates the elements of LIST and returns a string value
               with all characters in the opposite order.

                   print join(", ", reverse "world", "Hello"); # Hello, world

                   print scalar reverse "dlrow ,", "olleH";    # Hello, world

               Used without arguments in scalar context, reverse() reverses
               $_.

                   $_ = "dlrow ,olleH";
                   print reverse;                              # No output, list context
                   print scalar reverse;                       # Hello, world

               Note that reversing an array to itself (as in "@a = reverse
               @a") will preserve non-existent elements whenever possible,
               i.e., for non magical arrays or tied arrays with "EXISTS" and
               "DELETE" methods.

               This operator is also handy for inverting a hash, although
               there are some caveats.  If a value is duplicated in the
               original hash, only one of those can be represented as a key in
               the inverted hash.  Also, this has to unwind one hash and build
               a whole new one, which may take some time on a large hash, such
               as from a DBM file.

                   %by_name = reverse %by_address;  # Invert the hash   

论坛徽章:
0
4 [报告]
发表于 2012-11-19 19:01 |只看该作者
回复 1# stesting

输入数组的元素只有一个
  1. print "$line[0]"
复制代码
就可以看出来了
   

论坛徽章:
0
5 [报告]
发表于 2012-11-20 11:09 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
6 [报告]
发表于 2012-11-20 16:23 |只看该作者
o ,明白谢谢各位
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP