in reply to use constant for strings
will print the name of the capitol, anduse constant WI => "WISCONSIN"; use constant ILLINOIS => "IL"; my %capitol_map = ( WISCONSIN => "Madison", ILLINOIS => "Springfield", ); my $abbrev = WI; if ( exists $capitol_map{$abbrev} ) { print "capitol = $capitol_map{$abbrev}\n"; } else { print "False" }
will not.use constant WI => "WISCONSIN"; use constant ILLINOIS => "IL"; my %capitol_map = ( WISCONSIN => "Madison", ILLINOIS => "Springfield", ); #THE LINE BELOW WAS CHANGED my $abbrev = "WI"; if ( exists $capitol_map{$abbrev} ) { print "capitol = $capitol_map{$abbrev}\n"; } else { print "False" }
update:Hrm.. maybe I missed the fact that the OP might have wanted the WISCONSIN in the hash to become WI not the WI in the my $abbrev to become WISCONSIN ... so my answer would then be incorrect as i seem to be answering the wrong thing.
-enlil
|
|---|