in reply to accessing backreferences

Your problem is that $1...$3 are not indices in an array, but are read-only scalar variables generated by the system. Thus, $1 is not at all the same as $[1] (heh, heh) or something like that.

You want to use eval() to convert your iterator into something usable, like so:

perl -e "$a = qq(foo); $a =~ m/(foo)/; $s = 1; $xx = eval('\$$s');pri +nt $$xx; "

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re: Re: accessing backreferences
by merlyn (Sage) on Mar 09, 2001 at 23:23 UTC
    No, that's about as wrong as you can get. Don't use eval for that. See the other solutions in this thread for maintainable, workable, speedy, safe solutions.

    -- Randal L. Schwartz, Perl hacker