I'd like to pass the result of a regex into a function, as the first of three parameters. For example:
my $str = 'abc';
PassRegex($str =~ /b/i, 'parm2', 'parm3');
The subroutine looks like this:
use Data::Dumper;
sub PassRegex {
print Dumper(\@_);
print "BoolExpr = $_[0]\n";
print "parm2 = $_[1]\n";
print "parm3 = $_[2]\n";
return;
}
This works fine when the regex evaluates to true (1); if I look at @_ inside the function, I see 1 as the 0th element. However, if I change the regex to /x/i, so that it evaluates to false (the empty string), then the 0th element of @_ seems to disappear. Data:Dumper shows a 0th element, but it is empty -- completely empty, not the empty string -- and $_[0] returns the second parameter. Contrast this case to the case where I explicitly pass in the empty string to the function, and @_ contains what one would expect.
My question is, what do regexes that don't produce a match actually return, if not the empty string? Also, I realize that there are probably other ways to accomplish what I'm trying to do -- for example, I could quote the regex so that it would be evaluated inside the function -- but I'm curious about why this way doesn't work.