Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Perl substitution not working

by muba (Priest)
on Jun 21, 2012 at 00:45 UTC ( #977519=note: print w/replies, xml ) Need Help??


in reply to Perl substitution not working

My guess? Because the commas are each part of another element of @L1, because they had "notice", "[", "mpmstats:", or "\t" inbetween them.

Try this fix:

# ... if ( ($line =~ /notice/) && ($line =~ /rdy/) ) # Spaces to commas $line =~ s/ /,/g; # Get rid of "notice", "[", "mpmstats:", and tabs inside the line. $line =~ s/notice|\[|mpmstats:|\t//g; # Change the dreaded Triple Comma into the nice and smooth Single +Comma. $line =~ s/,,,/,/g; # Or even the following if you want to replace all multiple subs +equent commas by # just one: # $line =~ s/,,+/,/g; # Show me what I've got print $line; }

See how I wrote your [[] as \[? I think it's more readable that way. Also, regular expression understand \t just fine. There's no need to put it into a character class. And if ( ($line =~ /notice/) && ($line =~ /rdy/) ) { pretty much does the same thing as your two if statements. The inner parens are optional, but I prefer to write it that way.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://977519]
help
Chatterbox?
[Corion]: A good morning to everybody!
[Lady_Aleena]: Morning Corion.
[Corion]: I spent yesterday evening (and early night) in VR in Vanishing Realms, and can really recommend it
Discipulus is a very sad mornig anyway..
[Corion]: The title/"cover" image doesn't convey the comic/painted style, and the gameplay is really diverse, especially for a VR game

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-05-23 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?