ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:
When I have an array which comprises both strings and integers , then applying the sort function in below mentioned ways , gives different output. Could anyone please explain me on what basis the sorting is happening in the following two cases :
@arr = ("jack", 80, "martin", 3, "allan", 'george'); @sort = sort { $a cmp $b } @arr; print "@sort \n";
output :
3 80 allan george jack martin
If the sort function is changed to
@sort = sort { $a <=> $b } @arr ;
then the output changes to
jack martin allan george 3 80
Back to
Seekers of Perl Wisdom