Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am attempting to remove 3 commas from the file below but it is not working.
#!/usr/bin/perl use strict; use warnings; my @data; my @line; open(FH, "error_log"); @data = <FH>; foreach $line (@data) { if ($line =~ /notice/) { if ($line =~ /rdy/) { $line =~ s/ /,/g; my @L1 = split(/notice|[[]|mpmstats:[\t]/, $line); foreach $line (@L1) { $line =~ s/,,,/,/g; print @L1; } } } }
My output is as follows.
Wed,Jun,13,10:23:35,2012,,,rdy,769,busy,31,rd,0,wr,22,ka,6Why is the s/,,,/,/g; not substituting the single comma?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl substitution not working
by syphilis (Archbishop) on Jun 21, 2012 at 00:48 UTC | |
|
Re: Perl substitution not working
by 2teez (Vicar) on Jun 21, 2012 at 00:40 UTC | |
|
Re: Perl substitution not working
by Lotus1 (Vicar) on Jun 21, 2012 at 00:50 UTC | |
|
Re: Perl substitution not working
by muba (Priest) on Jun 21, 2012 at 00:45 UTC | |
|
Re: Perl substitution not working
by frozenwithjoy (Priest) on Jun 21, 2012 at 00:44 UTC | |
by muba (Priest) on Jun 21, 2012 at 00:53 UTC |