I have a perl question for y'all, this program:
#!/usr/bin/perl
my %days_in_month = (
"Jan" => 31,
"Feb" => 29,
"Mar" => 31,
"Apr" => 30,
"May" => 31,
"Jun" => 30,
"Jul" => 31,
"Aug" => 31,
"Sep" => 30,
"Oct" => 31,
"Nov" => 30,
"Dec" => 31 );
foreach $day (%days_in_month) {
print "$days_in_month{$day} days hath $day\n";
}
gives this output:
[ceidem@SHARPAM ~/src/perl]$ cal.pl
31 days hath Oct
days hath 31
31 days hath Dec
days hath 31
31 days hath Mar
days hath 31
29 days hath Feb
days hath 29
31 days hath Jan
days hath 31
30 days hath Nov
days hath 30
31 days hath May
days hath 31
31 days hath Aug
days hath 31
30 days hath Sep
days hath 30
31 days hath Jul
days hath 31
30 days hath Apr
days hath 30
30 days hath Jun
days hath 30
[ceidem@SHARPAM ~/src/perl]$
Where does the extraneous "days hath n" come from?
TIA,
- chris
New title per NTC - dvergin 2002-05-01
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.