in reply to Print hash except first value
Some alternatives:
my $first = 1; for my $n (sort { $hash{$a} <=> $hash{$b} } keys %hash){ if ($first) { $first = 0; next; } ... }
my @names_by_val = sort { $hash{$a} <=> $hash{$b} } keys %hash; shift(@names_by_val); for my $n (@names_by_val) { ... }
my @names_by_val = sort { $hash{$a} <=> $hash{$b} } keys %hash; for my $n (@names_by_val[1..$#names]) { ... }
A hash isn't needed at all.
my %hash; foreach my $n (@names){ my $r = int(rand($range))+$min; $hash{$n}=$r; } my @names_by_val = sort { $hash{$a} <=> $hash{$b} } keys %hash;
can be replaced with
use List::Util qw( shuffle ); my @shuffled_names = shuffle @names;
Update: Doesn't answer the question.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Print hash except first value
by xhunter (Sexton) on Dec 21, 2008 at 17:37 UTC | |
Re^2: Print hash except first value
by joec_ (Scribe) on Dec 20, 2008 at 22:23 UTC | |
by ikegami (Patriarch) on Dec 20, 2008 at 22:25 UTC | |
by joec_ (Scribe) on Dec 20, 2008 at 22:34 UTC | |
by ikegami (Patriarch) on Dec 20, 2008 at 22:36 UTC | |
by joec_ (Scribe) on Dec 20, 2008 at 22:44 UTC | |
by jwkrahn (Abbot) on Dec 21, 2008 at 03:52 UTC | |
by joec_ (Scribe) on Dec 21, 2008 at 13:20 UTC | |
| |
by swampyankee (Parson) on Dec 21, 2008 at 17:38 UTC |