Using variable as the key to get the value stored in a hash : key « Hash « Perl






Using variable as the key to get the value stored in a hash

   

#!/usr/bin/perl -w

use strict;

my $who = "C";

my %where = (
     A => "AA",
     B => "BB",
     C => "CC",
     D => "DD"
);

print $where{A}, "\n";
print "$who lives in $where{$who}\n";

   
    
    
  








Related examples in the same category

1.Determine if the value for the key is defined
2.Hash Key and Value Retrieval
3.Is a key defined in a hash
4.Is a key in a hash
5.Is hash key defined and existed