![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^2: question about: my $a AND sort {$a <=> $b} keys %hashby AnomalousMonk (Bishop) |
on Aug 06, 2015 at 13:58 UTC ( #1137684=note: print w/replies, xml ) | Need Help?? |
You unfortunately just stumbled into one of the genuine design-flaws of the Perl interpreter ... The basic design flaw is lexicalizing (if that's even a word) the name of the $a special variable so that the homonym package variable becomes invisible (and also running without strictures or warnings).
I don’t recall if using a separate sort-comparison sub, rather than an inline anonymous, will address the matter or not. Can someone else please answer that? I'm not sure why you can't answer the question yourself, but yes, a properly constructed named comparison function will sidestep the problem (update: although it would be better to address the issue directly): Please see sort. Update: Changed code examples to eliminate keys %hash expressions of OPed code and use a plain array for unsorted elements. Give a man a fish: <%-(-(-(-<
In Section
Seekers of Perl Wisdom
|
|