Example 8-9. examples/arrays/sort.pl #!/usr/bin/perl
use strict;
use warnings;
my @data = (11, 23, 12);
my @sorted = sort @data;
my @sorted_ascii = sort {$a cmp $b} @data;
my @sorted_numeric = sort {$a <=> $b} @data;
my @sorted_by_length
= sort {length($a) <=> length($b)} @data;
my @sorted_by_length_and_ascii
= sort {
length($a) <=> length($b)
or
$a cmp $b
} @data;
my @sorted_by_abc = sort {lc($a) cmp lc($b)} @data;
my @sorted_abc_ascii
= sort {
lc($a) cmp lc($b)
or
$a cmp $b
} @data;
If you are interested in on-site trainings by the author, please
contact me directly.
|