
nataT_T
New User
Jul 20, 2011, 2:29 PM
Post #1 of 2
(340 views)
|
|
Access key hash using variable
|
Can't Post
|
|
Hi guys A variable is given from user to access the number of days for a specific month. Is it possible to use a variable as a key in a hash? Thanks in advance # List here: %month_days = ( "January" => 31, "February" => 28, "March" => 31, "April" => 30, "May" => 31, "June" => 30, "July" => 31, "August" => 31, "September" => 30, "October" => 31, "November" => 30, "December" => 31); #Ask for month. print "Enter month\n"; $month=<>; #Get number of days from hash $numberDays = $month_days{"$month"}; #This is not working print "Number of days in $month is $numberDays " #Does not print anything U_U |