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.
In reply to Re: Print hash except first value
by ikegami
in thread Print hash except first value
by joec_
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |