I'll comment on the regular expression:
# 1 2 3
+ 4 5 6
$line=~ /^(\w+)::(gmdate):(20\d\d-[01]\d-[0123]\d [012]\d:[0-6]\
+d):(\w+):(\w*):(.*)/
The stuff parentheses fill in $1 to $6. This is commonly called "capturing parentheses", and documented in perlre.
The first pair of parentheses captures a sequence of characters (\w+), like info.
The second pair captures the literal string gmdate. We could have left the capture out, but maybe we want to expand the RE later to allow for other strings in that place.
The third pair captures something that looks like a YYYY-mm-dd HH:MM timestamp, with some basic validation thrown in:
- 20\d\d matches four digits that start with 20. For timestamps, this is sensible as it is unlikely that you will have to process timestamps from 1999, or timestamps in 2100.
- -[01]\d matches a minus followed by the digits 0 or 1, followed by another digit. This will capture something that vaguely looks like a month number, allowing numbers from 00 to 19. This is not exactly a month, but close enough. Especially this will break if somebody puts in a YYYY-dd-mm timestamp.
- -[0123]\d matches a minus followed by the digits 0,1,2 or 3. This will match the day part of the date. It makes no validation as to the months, so the 30th February or 31st April will still match.
- [012]\d:[0-6]\d will match something that vaguely looks like HH:MM, with the hour between 00 and 29 and the minute between 00 and 69. I allow for the 60 minutes because I mistook it for seconds, and depending on the exact specifics of UTC, you can have timestamps with 60 or 61 seconds I believe. In any case, it's better be lenient here.
If you can tell us where exactly you have problems with the regular expression, that will help us help you better.
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.