in reply to What happens with empty $1 in regular expressions? (was: Regular Expression Question)
my $sss = "M9"; if ($sss =~ m/(\d+)/){ print "Value Matched on: $1\n"; # prints Value Matched on: 9 } $sss = "Mm"; if ($sss =~ m/(\d+)/){ print "Value Matched on: $1\n"; # if statement is not entered } print "\$1 holds $1!\n";
The generally accepted wisdom is to use conditionals exclusively if you're capturing things. You could also add an else clause, undefining $1.
|
|---|