免费注册 查看新帖 |

Chinaunix

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

Is there a function that works in opposite way to chop/chomp? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-07-07 14:42 |只看该作者 |倒序浏览
Hi,

I just want to append newline character to each element of an array. Is there an existing function to use?

论坛徽章:
0
2 [报告]
发表于 2011-07-07 14:47 |只看该作者
join

论坛徽章:
0
3 [报告]
发表于 2011-07-07 14:50 |只看该作者
use 5.010 and say for @your_array;

论坛徽章:
0
4 [报告]
发表于 2011-07-07 14:50 |只看该作者
join
wind_ch 发表于 2011-07-07 14:47



    join is functionally opposite to split!

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
5 [报告]
发表于 2011-07-07 14:51 |只看该作者
本帖最后由 yinyuemi 于 2011-07-07 15:00 编辑

回复 1# nhw_cs


  @arr= ( join "\n", map {$_} @arr,"")

论坛徽章:
0
6 [报告]
发表于 2011-07-07 14:52 |只看该作者
use 5.010 and say for @your_array;
x9x9 发表于 2011-07-07 14:50



    What? Explain further please? Your answer makes little sense to me.

论坛徽章:
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
7 [报告]
发表于 2011-07-07 14:54 |只看该作者
Hi,

I just want to append newline character to each element of an array. Is there an existing fun ...
nhw_cs 发表于 2011-07-07 14:42



just add the "\n" when you want output or assign to another one
print "$_\n" foreach(@array);

join also can do that
print join "\n",@array;
(note: it didn't add "\n" in last element)

论坛徽章:
0
8 [报告]
发表于 2011-07-07 15:02 |只看该作者
回复  nhw_cs


  @arr= ( join "\n", map {$_} @arr,"")
yinyuemi 发表于 2011-07-07 14:51



    It doesn't work either this way. The newline is not added to the last element !

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
9 [报告]
发表于 2011-07-07 15:03 |只看该作者
本帖最后由 yinyuemi 于 2011-07-07 15:04 编辑

回复 8# nhw_cs


    我已经做了修改,please try again

   @arr=(join "\n", @arr,"")

论坛徽章:
0
10 [报告]
发表于 2011-07-07 15:04 |只看该作者
What? Explain further please? Your answer makes little sense to me.
nhw_cs 发表于 2011-07-07 14:52
  1. use 5.010;
  2. say for @your_array;
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP