Mega Code Archive

 
Categories / Perl / Hash
 

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";