Hi; I'm having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
I'm looking at http://perldoc.perl.org/functions/sort.html I have an array that I want to have sorted numerically and descending. The array is composed of elements that look like the following regex: ^\d+\t\[a-zA-Z0-9]+$ I always have "use strict" at the top of my Perl scripts. If I try: my @articles = sort {$b <=> $a} @files; I get error(s)/warning(s) that the data is not numeric. if I try: my @articles = sort {$b cmp $a} @files; I will get numbers sorted as letters, not numerically. I tried to understand the sort perldoc page further down, but did not grok it at all. What I did as a workaround was to implement my own extremely brute-force sort routine, which works, but is very ugly. Since I have very few elements (perhaps as many as a couple dozen), the inefficiency is immaterial. I'd rather that my code be correct, intuitive and elegant (and efficient). Thanks, Ken Wolcott -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/