develooper Front page | perl.perl5.porters | Postings from September 2014

[perl #15667] exchange value of $a,$b without $temporary variable

Thread Previous
From:
Father Chrysostomos via RT
Date:
September 19, 2014 03:07
Subject:
[perl #15667] exchange value of $a,$b without $temporary variable
Message ID:
rt-4.0.18-31775-1411096036-125.15667-15-0@perl.org
On Sat Jul 27 05:06:39 2002, nospam-abuse@ilyaz.org wrote:
> [A complimentary Cc of this posting was sent to
>  Martien Verbruggen
> <mgjv@tradingpost.com.au>], who wrote in article
> <slrnak1205.n5.mgjv@verbruggen.comdyn.com.au>:
> > But why would you consider using anything but the ($a, $b) = ($b, $a)
> > expression? It's clearly the clearest, and will work for anything.
> 
> IIRC, this construction (well, a similar one) has subtle problems with
> aliasing present.  Found this the hard way with File::Find...
> 
> perl5.6.0 -wle 'BEGIN{ *a=\$a::a; *b = \$b::b } \
>                 ($a, $b) = (2,3); print "$a $b"; \
>                 ($a::a, $b::b) = ($b, $a); print "$a $b"'
> 2 3
> 3 3
> 
> I think this may be considered as a bug, the parser has enough info to
> detect this...
> 
> Hope this helps,

Twelve years after the report, this is finally fixed, in commit ff2a62e0c.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: stalled
https://rt.perl.org/Ticket/Display.html?id=15667

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About