I crave some benevolence from the monks. I'm tying to teach myself some basic text parsing. I'm trying to test for if a part of a month exists in a string, having split the string into tokens and then the tokens into substring of 3 characters long. If it does exist, then I'm trying to swap it to a number using a hash. I keep getting a use of an uninitialised value in the concatenation.
sub num_month {
my $date = shift;
my %months = (JAN => '01', FEB => '02', MAR => '03',
APR => '04', MAY=> '05', JUN => '06',
JUL => '07', AUG => '08', SEP => '09',
OCT => '10', NOV => '11', DEC => '12');
my @tokens = split (" ", $date);
my $date;
foreach my $num (@tokens) {
my $strBegin = substr($num, 0, 3);
my $date =~ s/$strBegin/$months{uc $strBegin}/;
}
return $date;
}
As this pattern may or may not exist in the line, I just wanted to effect a light swap using a hash rather than trying to call Date::parse since there is no standard pattern.
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.