http://qs321.pair.com?node_id=543175

Gavin has asked for the wisdom of the Perl Monks concerning the following question:

Hi Bretheren,
I was hoping the following would enable me to print out from the input percentage from the hash by key / value pairs. The hash is sorted in a specific order, but it is not coming out in that order. I need to be able to hold the UPDATE insertion order to output.
Any ideas will be much appreciated.
Gavin
my $Percent = <STDIN>; my $per = $Percent/100;#percent as decimal my $pairs = (keys %lineFinal);# pairs of key/value my $counter = 0;# zero counter my $amount_to_print = int($per * $pairs); foreach my $key ( keys %lineFinal) { if ($counter < $amount_to_print) { print $key, ' ', $lineFinal{$key}, "\n"; #print OUTPERC $key, ' ', $lineFinal{$key}, "\n"; print OUTPERC "$key\t $lineFinal{$key}\n"; } else { last; } $counter++; }