免费注册 查看新帖 |

Chinaunix

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

chop and chomp的区别! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-06-05 16:15 |只看该作者 |倒序浏览
RT !

帮忙说的详细点~!
多谢多谢!


我自己测试了一下,很糊涂: chomp 得到的是记录数,比如:
  1. [root@localhost perl]# cat chomp
  2. #!/usr/bin/perl
  3. $test_line=<STDIN>;
  4. $result_chomp=chomp($test_line);
  5. $result_chop=chop($test_line);
  6. print $result_chomp,"\n========================\n";
  7. print $result_chop,"\n";
  8. [root@localhost perl]# perl chomp
  9.   asldkja sdqjjdlkasjd qjljsldk jasd         //结尾没有空格,直接就是回车
  10. 1
  11. ========================
  12. d
  13. [root@localhost perl]# perl chomp
  14.   ajsdklja sd sjajsdjasdjasd  akslkdas   //结尾有空格
  15. 1
  16. ========================

复制代码

论坛徽章:
0
2 [报告]
发表于 2011-06-05 16:26 |只看该作者
chop VARIABLE
          chop( LIST )
          chop    Chops off the last character of a string and returns
                  the character chopped.
Note that "chop" returns the last character.


     chomp VARIABLE
          chomp( LIST )
          chomp   This safer version of "chop" removes any trailing
                  string that corresponds to the current value of $/
                  (also known as $INPUT_RECORD_SEPARATOR in the
                  "English" module).  It returns the total number of
                  characters removed from all its arguments

论坛徽章:
0
3 [报告]
发表于 2011-06-05 16:28 |只看该作者
大致说的就是chop和chomp都是删除最后的那个字符

chop返回的值是最后的那个被删的字符
chomp返回的值是删除字符的数目

论坛徽章:
0
4 [报告]
发表于 2011-06-05 17:24 |只看该作者
perldoc
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP