in reply to Printing a hash from a foreach loop
Where does the extraneous "days hath n" come from?It comes from a hash value being used as a key. This is because when a hash is in a list context it evaluates to a list of it's keys and values in alternating pairs. So you were iterating through both keys and values, and when the values were used as keys you were getting 'extraneous' output because they had no corresponding value in the hash. What you intended to do was this.
You'll probably want to read up on types in perl and how to use them effectively.foreach my $day (keys %days_in_month) { print "$days_in_month{$day} days hath $day\n"; }
_________
broquaint
|
|---|