ktl has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use warnings; use strict; my $should_be = <<"END_SHOULD_BE"; input is: , , 1 , , , 2 , , , , 3 , , , , , 4 , , , , , , 5 , , , , , , , 6 , , , , , , , , 7 , , , , , , , , , 8 , , , , , , , , , , 9 , , , , , , , , , , , 10 output should be: ,, 1 ,,, 2 ,,,, 3 ,,,,, 4 ,,,,,, 5 ,,,,,,, 6 ,,,,,,,, 7 ,,,,,,,,, 8 ,,,,,,,,,, 9 ,,,,,,,,,,, 10 output is: END_SHOULD_BE print "$should_be"; while (<DATA>) { s{, +,}{,,}g; print $_; } __DATA__ , , 1 , , , 2 , , , , 3 , , , , , 4 , , , , , , 5 , , , , , , , 6 , , , , , , , , 7 , , , , , , , , , 8 , , , , , , , , , , 9 , , , , , , , , , , , 10
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: remove spaces only between commas
by ikegami (Patriarch) on Sep 21, 2007 at 17:15 UTC | |
by Anonymous Monk on Sep 21, 2007 at 17:37 UTC |