in reply to Passing regex result into function
PassRegex($str =~ /b/i, 'parm2', 'parm3');I believe that regex is evaluated in list context, not scalar context. In that case, the m operator returns an empty list when there is no match. From perlop:
An empty list is a list with no items. So, when there is no match, you actually pass a list of 2 items to your sub, not 3. You could use this to force scalar context:an empty list is returned upon failure.
Or, be more explicit with:PassRegex(0+($str =~ /x/i), 'parm2', 'parm3');
PassRegex($str =~ /x/i ? 1 : 0, 'parm2', 'parm3');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing regex result into function
by choroba (Cardinal) on Apr 17, 2016 at 07:00 UTC |