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

pos() returning undef when match is not successful?

Thread Next
From:
Stas Bekman
Date:
November 26, 2004 17:04
Subject:
pos() returning undef when match is not successful?
Message ID:
41A7D2AC.3050505@stason.org

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

% 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
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About