in reply to Regex failure interpretation

I find it quite logical $1 contains the last capture. After all, you'd expect $v to be 3 in
$v = $_ for 1, 2, 3;
as well (I hope).

Here's a way to capute the first character:

$ perl -wle 'm[^(?{undef $var})(?:([01])(?{$var //= $^N}))+$] and print "$_: '"'"'$var'"'"'" for qw[ 0 1 00 11 10 01 012]' 0: '0' 1: '1' 00: '0' 11: '1' 10: '1' 01: '0'

Abigail

Replies are listed 'Best First'.
Re: Re: Regex failure interpretation
by BrowserUk (Patriarch) on Mar 20, 2004 at 02:07 UTC

    Now I've seen the explanations, I agree, it is logical. That said, I still wish that captures were pushed to a global array (say @^N) rather than to $1 $2 etc.

    If @^N contained the captures pushed in the order they were captured it would alleviate many of the games one has to play when capturing variable numbers of things.

    (BTW. There are easier ways of correcting the regex:)


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail