Although I would not really recommend this, you could also use split if you really wanted to:$ perl -e '@words = ("one\n","two\n","three\n","four\n","five\n","six\ +n",); chomp @words; print join";", @words;' one;two;three;four;five;six
Or perhaps a regex:$ perl -e '@words = ("one\n","two\n","three\n","four\n","five\n","six\ +n",); @words = map {split /\n/, $_ } @words; print join";", @words;' one;two;three;four;five;six
Or split again, but without a map this time:$ perl -e '@words = ("one\n","two\n","three\n","four\n","five\n","six\ +n",); @words = map {s/\n//; $_} @words; print join";", @words;' one;two;three;four;five;six
Or, if you don't want to use the join function:$ perl -e '@words = ("one\n","two\n","three\n","four\n","five\n","six\ +n",); $_ = (split /\n/)[0] for @words; print join";", @words;' one;two;three;four;five;six
Well, I could probably offer at least a dozen other solutions mixing the various ideas above or introducing new ones, but I hope you get the idea of how to do the things in a much more concise way than what you had.$ perl -E '@words = ("one\n","two\n","three\n","four\n","five\n","six\ +n",); local $" = ";"; $_ = (split /\n/)[0] for @words; say "@words";' one;two;three;four;five;six
In reply to Re: split on newline
by Laurent_R
in thread split on newline
by tbone654
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |