in reply to Pattern matching and setting the match to a variable
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.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.
Update: Whoops, missed that you were doing that implicitly. Kyle has the correct answer.
--starX
www.axisoftime.com
|
---|