On Sun, Apr 13, 2008 at 4:12 PM, John W. Krahn <[EMAIL PROTECTED]> wrote:
snip
> > >  push @bad, "$3_$5_$4_$6_$2_$1";
> > >
> > snip
> >
> > I believe they would come out roughly the same in terms of
> > performance, but, in general, I don't trust $1, $2, etc outside of a
> > substitution.  I have been bitten by interrupts that modified/cleared
> > them before.
> >
>
>  You snipped out the part where I changed s{}{} to m{}.
snip

That is because it is irrelevant.  Of course, it is a match not a
substitution, you don't tend to use $1, $2, etc. after a substitution.
 My issue is with the use of a match followed by the use of $1, $2,
etc.  Code can execute between the match and the interpolation (think
signal handler).  That code can (and at least once has in my case)
change or reset $1, $2, etc.  Therefore, I no longer trust $1, $2,
etc. outside of a substitution.  I tend to say things like

my ($foo, $bar, $baz) = /(\S+)\s+(\S+)\s+(\S+)/;

instead.  This also has the benefit of being self-documenting (if you
name the variables correctly).



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to