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 returned upon failure.
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:
PassRegex(0+($str =~ /x/i), 'parm2', 'parm3');
Or, be more explicit with:
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
    > force scalar context

    I'd use scalar for that:

    scalar($str =~ /x/i)

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,