in reply to Re: Re: value returned on m// failure
in thread value returned on m// failure

m// returns true or false in scalar context. Perl defines:

NAMEValue as StringValue as NumberPerl Internal Variable
true"1"1PL_sv_yes
false""0PL_sv_no

For evidence, see the source code module perl.c where PL_sv_yes and PL_sv_no are initialized. Also see the pp_match code in pp_hot.c where RETPUSHYES and RETPUSHNO are used to return a boolean value when invoked in scalar context without /g.

  • Comment on Re: Re: Re: value returned on m// failure

Replies are listed 'Best First'.
Re: Re: Re: Re: value returned on m// failure
by parv (Parson) on Dec 31, 2002 at 05:41 UTC

    ah, so that is why bitwise AND operation w/ numeric** 1 yields 0 whenever following fails...

    (defined $var && $var =~ m/regex/) & 1

    ...which otherwise would have produced an empty string. thanks mark.

    ** per perlop, an numeric operand implies numeric bitwise operation; per the table mark posted, false value is zero in numeric context.