in reply to how to convert new line to ","
#!/usr/bin/perl -w use strict; { local $/; my $line = <DATA>; $line =~ s/\b\n\b/, /g; $line =~ s/\n{2,}/\n/g; print $line; } __DATA__ 1,111 22,22 33,33 4,444 5,555 66,66 45,54 4,554 4,654 ----------- Output: 1,111, 22,22, 33,33 4,444, 5,555, 66,66 45,54, 4,554, 4,654
Well seen moritz !
Update:
#!/usr/bin/perl -w use strict; { local $/; my $line = <DATA>; $line =~ s/\n(?!\n)/, /g; $line =~ s/\n{2,}/\n/g; print $line; } __DATA__ !1,111 22,22? .33,33// 4,444!! ::5,555 &&66,66 45,54@@ 4,554<< ``4,654{ --- Output: !1,111, 22,22?, .33,33// , 4,444!!, ::5,555, &&66,66 , 45,54@@, 4,554<<, ``4,654{
hth,
PooLpi
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to convert new line to ","
by moritz (Cardinal) on Jul 24, 2008 at 14:30 UTC |