So, when you're looking for the date range, you can find the "Analysis Date Range", but then how do you decide what is the date coming after that?
I would say that you're looking for:
- First, the string "Analysis Date Range : " with an arbitrary amount of whitespace around the ':' (/Analysis Date Range\s+:\s+/)
- Then, at least one digit, which we want to remember (/([0-9]+)/)
- Then, a slash (which needs a backslash to escape it) followed by at least one digit, and record the digits but not the slash (/\/([0-9]+)/)
- Then, another slash followed by at least one digit, and again record the digits not the slash (/\/([0-9]+)/)
- And the rest doesn't matter
Combining that all into one:
# i modifer to make it case insensitive, just in case.
if ($line =~ /Analysis Date Range\s*:\s*([0-9]+)\/([0-9]+)\/([0-9])+/i
+)
{
print "I found an Analysis date with month/day $1, $2 in year $3\n";
}else{
print "This line did not have an analysis date that I recognize in i
+t\n";
}
Another way to go, would be to grab larger chunks and then split them later:
- "Analysis Date Range : "
-
- Then a pile of digits-and-slashes (start date) ([0-9\/]+)
- Then whitespace and digits-and-colons (start time) \s([0-9:]+)
- Then more whitespace and some digits-and-slashes (end date)
- Finally, whitespace then digits-and-colons (end time)
PS: Is that date string "month day year" or "day month year"?
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.