Re: New Perl Quiz of the Week mailing list perl-qotw

[email protected] (Gareth McCaughan)
Newsgroups perl.golf
Organization International Pedant Conspiracy
Message-ID <200210212157.59871@gjm>
On Monday 21 October 2002 7:56 pm, you wrote:
> En op 21 oktober 2002 sprak Gareth McCaughan:
> > I'm feeling very dim. What's wrong with the much simpler
> >
> >     sub subst { (my $a=shift) =~ s/\$\d+/eval$&/eg; $a; }
>
> You have to replace '$1' by the actual value of $1. If you try that
> with a regex, $1 is changed. In your case, $1 (and $2, $3 etc.) is
> undefined.

D'oh, of course.

What's particularly embarrassing is that I *tested* it.
How could that possibly have worked, I hear you ask?
Simple. Excerpt from my little test program:

    print subst("$2, $1 and $3"), "\n";

Aieeee! :-)

-- 
g
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.