Friday, 9 December 2022

how to print the contents of perl hash?

 

Method1

 print "$_ $h{$_}\n" for (keys %h);


Method2:
 
while (my ($k,$v)=each %h){print "$k $v\n"}

Method3:
 
print "@{[%hash]}";

Method4:
 
print map { "$_ $h{$_}\n" } keys %h;

Method5:
 
print "$_ $h{$_}\n" for keys %h

Method6:
 
foreach(keys %my_hash) { print "$_ / $my_hash{$_}\n"; }

Method7:
 
map {print "$_ / $my_hash{$_}\n"; } keys %my_hash;

Method8:
 
print map {$_ . " "} %h, "\n";

Labels: , ,