Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: how to comment the lines if found a match

by gwadej (Chaplain)
on Dec 05, 2008 at 21:59 UTC ( #728397=note: print w/replies, xml ) Need Help??

in reply to Re^2: how to comment the lines if found a match
in thread how to comment the lines if found a match

You are misunderstanding the use of grep.

In your example, grep will always return $l unless $m happens to be 0 or an empty string.

Instead of grep, you probably want a regular expression.

if($l =~ /\Q$m\E/) { print "We matched\n"; print OF "$$l"; }

You probably also want to use chomp in the outer loop to remove the line ending from $m.

You are also writing the file multiple times with different lines commented each time. You might want to generate a list of the expressions to match at the beginning and then loop over the file once.

G. Wade

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://728397]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2023-11-30 03:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found