in reply to backreference question.

it is the list context in the   @t1 = ... m//g   which gives you multiple results for just that single match. I does, however, not create a loop.

That's why it doesn't work in your while loop.   $1   and   $2   get filled only once, because without the list context, that's what the matching operator   m   does in those cases.

Update: Wrong thought, obviously.

Replies are listed 'Best First'.
Re: Re: backreference question.
by davidj (Priest) on Jun 01, 2004 at 00:39 UTC
    I'm not sure that is correct. The following code seems to work the way he is expecting his to:
    use strict; my $str = "1 2 3 4 5 6 7 8 9 10"; my (@a, @b); while($str =~ m/(\d+) (\d+)/g) { push @a, $1; push @b, $2; } print "\@a = @a\n"; print "\@b = @b\n";
    output:
    @a = 1 3 5 7 9 @b = 2 4 6 8 10

    I'm curious
    davidj