develooper Front page | perl.perl5.porters | Postings from November 2004

pos() returning undef when match is not successful?

Thread Next
Stas Bekman
November 26, 2004 17:04
pos() returning undef when match is not successful?
Message ID:

% perl -le '$_ = "a"; /a/g; print pos'

% perl -le '$_ = "a"; /b/g; print pos'

prints nothing (returns undef), I'd expect that it returns 0.

Do I miss something? Didn't find any mentioning of undef being returns 
instead of 0 in the perlre/perlfunc docs. Seems to be the case with all perls.

is that the case when one needs to check the success of the match before 
attempting to use pos()? in which case, it'd be nice to add a note to 
'perldoc -f pos' to say:

pos() is valid only if the match was successful.

IMHO, it's much simpler to simply return 0 if there was a failure.

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About