in reply to Re: split on newline
in thread split on newline
You could save yourself some typing when initialising @words by using a HEREDOC and split with a look-behind.
$ perl -Mstrict -Mwarnings -E ' my @words = split m{(?<=\n)}, <<EOL; one two three EOL say qq{$_-----} for @words;' one ----- two ----- three ----- $
So, taking the whole thing together.
$ perl -Mstrict -Mwarnings -E ' say join q{;}, map { chomp; $_ } split m{(?<=\n)}, <<EOL; one two three EOL' one;two;three $
I hope this is of interest.
Update: Removed the $PS2 prompts fromthe second example for easier copy'n'paste.
Cheers,
JohnGG
|
|---|