in reply to how to print top 5 elements from a hash
Hash will not be sorted by itself. Do sort based on key and take top 5 elements and print the hash.
use strict; use warnings; my %hash=(key6=>'value6',key2=>'value2',key1=>'value1',key3=>'value3', +key4=>'value4',key5=>'value5'); my @arr=sort keys %hash; print map{$_.'=>'.$hash{$_}."\n"}@arr[0..4];
|
|---|