[Melbourne-pm] Regexps - how does the lexical scope of capture buffers work? (Was: Regexp: What's the right way to do this?)

Peter Vereshagin peter at vereshagin.org
Wed Oct 17 22:41:52 PDT 2012


Hello.

2012/10/18 10:33:35 +1100 Nathan Bailey <nathan.bailey at monash.edu> => To Michael G Schwern :
NB>    if (($start_time) = m#^\s*(\d+:\d+) -#) {

NB> My first question is really a language design one. Regexp evaluations short circuit on failure; why don't if statement assignments do the same?

Perhaps for '=~' operator no any variable changes when regex doesn't match.
And returns empty array in array context.

But in the code above you have the assignment '=' operator. So IMO in the case
the regex doesn't match you have this:

    if ( ($start_time) = () ) {

thus effectively undef()ining the scalar variable.

--
Peter Vereshagin <peter at vereshagin.org> (http://vereshagin.org) pgp: A0E26627 


More information about the Melbourne-pm mailing list