On Fri, Apr 21, 2006 at 01:12:35PM -0400, Uri Guttman wrote:
> >>>>> "a" == autrijus  <[EMAIL PROTECTED]> writes:
>   a> * S05: Oops, turns out I entirely read perlop.pod incorrectly;
>   a>   "it matches once only" means "it matches successfully once only",
>   a>   not "it performs the match once only".  Sorry, TimToady++'s
>   a>   original example of:
>   a>     (state $x) ||= / pattern /; 
>   a>   was correct.
>   a> +To reset the pattern, simply say C<$x = 0>.
> i did a fresh read of S05 due to all the recent activity (i will post
> some edits and questions soonish), but that example baffles me. how does
> it emulate the (never used by me) // of p5? my take would be that the rx
> would be or-assigned to $x and it would remain set through repeated
> calls to the outer sub (assuming a sub). what is the context that makes
> it match against $_ vs returning an rx. 

According to S05,  "a /.../ matches immediately in a value context
(void, Boolean, string, or numeric)" and since 

    (state $x) ||= / pattern /;

is very much the same as 

    state $x; $x = $x || /pattern/;

I'd say that's a "boolean context" and thus matches against $_ instead
of assigning the Regex object to $x.

Jonathan Scott Duff

Reply via email to