Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: question about: my $a AND sort {$a <=> $b} keys %hash ($::a & $::b)

by BrowserUk (Pope)
on Aug 06, 2015 at 21:04 UTC ( #1137754=note: print w/replies, xml ) Need Help??

in reply to Re: question about: my $a AND sort {$a <=> $b} keys %hash
in thread question about: my $a AND sort {$a <=> $b} keys %hash

That's why you should never use $a and $b as variable names.

Personally, I think instead of promoting a blanket ban on using lexical $a & $b -- which 9x% of code can use safely and usefully -- it would be better to change the documentation to show the use of:

my @sorted = sort{ $::a <=> $::b } @array;

which avoids the problem and clearly marks out the special usage of these variables for sort.

A simple change that would easily fix the problem.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
  • Comment on Re^2: question about: my $a AND sort {$a <=> $b} keys %hash ($::a & $::b)
  • Download Code

Replies are listed 'Best First'.
Re^3: question about: my $a AND sort {$a <=> $b} keys %hash ($::a & $::b)
by choroba (Archbishop) on Aug 06, 2015 at 21:44 UTC
    It doesn't work in a package, though.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1137754]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2020-09-24 08:01 GMT
Find Nodes?
    Voting Booth?
    If at first I don’t succeed, I …

    Results (132 votes). Check out past polls.