However if I add 'use strict;', I get the message 'Global symbol "$c" requires explicit package name ...'.

Yes, and if you named $a and $b something more reasonable, you'd hear about them too. (You only don't because they are special case variables used in sort blocks.) You can take care of that by declaring your globals though, and that's something you should be doing anyway. The following is safe under warnings and strict.

use warnings; use strict; my @x = (1,2,3); our ($a,$b,$c); (*a,*b,*c) = \(@x); $a = "f"; $b = "o"; $c = "o"; print sort {$b<=>$a} qw(17 11 13 29 31 37 3 2 7 5 19 23); print @x;
It also shows that using $a and $b is fine, despite also using them for a sort block. The problem with using $a and $b comes up when you have them declared as lexicals...
$ perl -le 'my $a=1; print sort {$b<=>$a} 1' Can't use "my $a" in sort comparison at -e line 1.
Since we all usually declare our variables as lexicals these days, the advice "don't use $a and $b" get dispensed without a lot of understanding about why it matters. Or when it doesn't.

Update: By the way, Data::Alias is a fine module and you shouldn't hesitate to use it if you can and it passes its tests. Sometimes people don't have control over what perl modules are available in their environment, particularly ones with an XS component. And sometimes modules have bugs, particularly platform specific ones, that prevent them being used. And sometimes adding a module isn't worth it when a couple extra lines of code will do. This is why I offered the old way of doing this. It's up to you to decide what is most appropriate in your situation.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re^3: referencing list by sauoq
in thread referencing list by pmilne

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.