Is there a function that works in opposite way to chop/chomp?
时间:2011-07-07
来源:互联网
I just want to append newline character to each element of an array. Is there an existing function to use?
作者: nhw_cs 发布时间: 2011-07-07
作者: wind_ch 发布时间: 2011-07-07
作者: x9x9 发布时间: 2011-07-07
wind_ch 发表于 2011-07-07 14:47
join is functionally opposite to split!
作者: nhw_cs 发布时间: 2011-07-07
回复 nhw_cs
@arr= ( join "\n", map {$_} @arr,"")
作者: yinyuemi 发布时间: 2011-07-07
x9x9 发表于 2011-07-07 14:50
What? Explain further please? Your answer makes little sense to me.
作者: nhw_cs 发布时间: 2011-07-07
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)
作者: jason680 发布时间: 2011-07-07
@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 !
作者: nhw_cs 发布时间: 2011-07-07
回复 nhw_cs
我已经做了修改,please try again
@arr=(join "\n", @arr,"")
作者: yinyuemi 发布时间: 2011-07-07
nhw_cs 发表于 2011-07-07 14:52
- use 5.010;
- say for @your_array;
作者: x9x9 发布时间: 2011-07-07
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28