my %word = (
'list' => 3,
'thats' => 1,
'value' => 2,
'an' => 1,
'would' => 1,
'the' => 3,
'at' => 1,
'if' => 2,
);
####
print "$_ => $word{$_}\n" for sort keys %word;
####
print "$_ => $word{$_}\n"
for sort {$word{$a} <=> $word{$b}} keys %word;
####
print "$_ => $word{$_}\n"
for sort {
$word{$b} <=> $word{$a} # sort values desc
|| # if same, then
$a cmp $b # sort keys asc
} keys %word
;
####
use strict;
use warnings;
my %word;
while () {
$word{"\L$_"}++ for map {s/\W//g;$_} split;
}
my $blank = delete $word{''};
printf("% 14s => %d\n",$_,$word{$_})
for sort {
$word{$b} <=> $word{$a} # sort values desc
|| # if same, then
$a cmp $b # sort keys asc
} keys %word
;
print "$blank 'errors' encountered\n";
__DATA__
I'm having a little trouble following the
documentation on pushing. It gives us the example:
for $value (LIST) {
$ARRAY[++$#ARRAY] = $value;
}
I'm assuming (LIST) should be an array list, and
if that's so it would have been nice if they said
that in the docs because at first I thought it was
a filehandle of some kind.