Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Pattern matching and setting the match to a variable

by starX (Chaplain)
on Feb 15, 2008 at 22:09 UTC ( [id://668261]=note: print w/replies, xml ) Need Help??


in reply to Pattern matching and setting the match to a variable

Try checking regular expression return values. Given this:
my $line = "I am the very model of a modern major general."; my $good_match = $line =~ m/major/; my $bad_match = $line =~ m/corporal/; print "$line\n" if $good_match == 1; # Prints the line. print "$line\n" if $bad_match == 1; # Doesn't print anything.
A successful regular expression match will return 1, so you can check against that. It prints the line if the match was made, and doesn't if it wasn't.

Update: Whoops, missed that you were doing that implicitly. Kyle has the correct answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-16 21:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found