in reply to Print not printing
Example of proper use of $a and $b:
my %monk = (); $monk{ Alice }{ XP } = 130; $monk{ Bert }{ XP } = 17; $monk{ Charles }{ XP } = 20; foreach my $monk ( sort ByXP( \%monk ) keys %monk ) { print "$monk\t$monk{ $monk }{ XP }\n"; } sub ByXP { # NB $a and $b are reserved for sort routines like this # <=> is a special sort operator for sorting by numeric value my $monastery = shift; ( $monastery -> { $a }{ XP } ) <=> ( $monastery -> { $b }{ XP } ); # note that the last line of a subroutine also # renders what is returned by default, although # sort routines even more magical than that! }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Print not printing
by brian_d_foy (Abbot) on Jun 24, 2005 at 16:17 UTC | |
by mrpeabody (Friar) on Jun 24, 2005 at 19:20 UTC | |
by anonymized user 468275 (Curate) on Jun 27, 2005 at 10:01 UTC |