in reply to Re: regex s/// using hash
in thread regex s/// using hash

i'm not using (?(cond)|..) but (? (?{code}) | (?!) )

i'm also a bit confused about the closures: being used in scope those regexp aren't returned so i can't see side-effect of using our or my, what am i missing?

Nice, i was looking for Regexp::List but i found Regexp::Assemble, i thought i was recalling wrongly. Oha

Replies are listed 'Best First'.
Re^3: regex s/// using hash
by ikegami (Patriarch) on Oct 16, 2007 at 13:57 UTC

    i'm not using (?(cond)|..) but (? (?{code}) | (?!) )

    Adding whitespace doesn't change what it is.

    i'm also a bit confused about the closures: being used in scope those regexp aren't returned so i can't see side-effect of using our or my, what am i missing

    A closure occurs when a sub persists longer than the scope in which it was created. The code in (?{code}), (??{code}) and (?(?{code})|..) is compiled into a sub. The regex persists beyond the scope in which it is created (to avoid needless recompiling of the regex), causing a closure.

    sub func_lex { my ($var) = @_; '' =~ /(?{ print("$var\n"); })/; } sub func_pkg { our ($var) = @_; '' =~ /(?{ print("$var\n"); })/; } func_lex('foo'); # foo func_lex('bar'); # foo !!! func_pkg('foo'); # foo func_pkg('bar'); # bar

    Update: Added func_pkg to example.

      oh, i understood what you mean!

      so thinking about that, seems to me that the solution isn't working at all, unless some effort.

      thanks

      Oha

        What solution isn't working?