in reply to Re: limiting scope of 'eval'??
in thread limiting scope of 'eval'??

Maybe because since at least 5.6.1, there isn't any real conflict.

#! perl -slw use strict; my( $a, $b ) = ( 'mya', 'myb' ); { our( $a, $b ) = ( 'oura', 'ourb' ); my @sorted = sort { $a <=> $b } map{ rand 100 } 0 .. 99; print "$a : $b"; } print "$a : $b"; __END__ P:\test>test oura : ourb mya : myb

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^3: limiting scope of 'eval'??
by bmann (Priest) on Aug 23, 2004 at 16:39 UTC
    It's still best to avoid gratuitous use of $a and $b.

    When $a and $b are declared properly, no conflict. But if you forget to declare them, you can quietly get action at a distance.

    #! perl -slw use strict; ( $a, $b ) = ( 'mya', 'myb' ); # imagine several lines of intervening code { our( $a, $b ) = ( 'oura', 'ourb' ); my @sorted = sort { $a <=> $b } map{ rand 100 } 0 .. 99; print "$a : $b"; } print "$a : $b"; __END__ C:\s>perl sortab.pl oura : ourb oura : ourb #no warnings, $a and $b are quietly changed

    The script dies if they are declared (with my instead of our) in the same scope as the sort routine:

    #! perl -slw use strict; my( $a, $b ) = ( 'mya', 'myb' ); { my( $a, $b ) = ( 'oura', 'ourb' ); my @sorted = sort { $a <=> $b } map{ rand 100 } 0 .. 99; print "$a : $b"; } print "$a : $b"; __END__ C:\S\pl>perl sortab.pl Can't use "my $a" in sort comparison at sortab.pl line 10.
    Update: Deleted extra code tag