Iterate hash : Hash Loop « Hash « Perl






Iterate hash

   

#!/usr/bin/perl

use strict;
use warnings;

my %hash = ('Key1' => 'Value1', 'Key2' => 'Value2');
print "$_ => $hash{$_} \n" foreach keys %hash;

foreach (sort values %hash) {
    print "Value: $_ \n";
}

   
    
    
  








Related examples in the same category

1.Loop through an associative array
2.Loop through an associative array While loop
3.Looping Over A Hash
4.Using foreach loops with hashes
5.While loop and hash key value pair
6.Using while and each function to output value in a hash