in reply to split and join, what's the clever way to do it
It's already been specified that specifying split's 3rd argument is the solution.
I just wanted to note the 3rd argument is also very useful to disable split's default of removing trailing blank fields.
>perl -le"print join '|', split /\|/, '|a|b|c||'" |a|b|c >perl -le"print join '|', split /\|/, '|a|b|c||', -1" |a|b|c||
I've always wondered why split is lossy by default, especially since I rarely if ever need the lossy behaviour. Either I don't care since I shouldn't be getting blank fields, or I want to keep the blank fields.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split and join, what's the clever way to do it
by cosmicperl (Chaplain) on Jan 30, 2008 at 18:06 UTC |