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

It doesn't return 1 for success. It returns the number of matches (or substitutions for s/// or tr///). If you're not using the g option, it stops on the first match and returns 1. I'm not really up on perl internals but I would guess undef is represented as a null pointer whereas a zero would require creation of an SV.

--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

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

    right you are. i know that s/// & tr/// return the number of matched; never occured to me that m// behaves the same.

    i goofed when i wrote that number 1 (be it as string or numeric) was being returned on a regex match. it just happens that only one thing was being matched.

    thanks for the clue.