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

In reply to Re^3: limiting scope of 'eval'?? by bmann
in thread limiting scope of 'eval'?? by ManFromNeptune

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.