Given that the data source is a big text field from a database table, I wouldn't count on newlines as being a reliable guide for separating the entries. Better to use a capturing split with a regex that will match the date string -- especially if you know what "username" has to look like (e.g. all alphnumerics, between 2 and 8 characters, always starting with a letter, or whatever).
my $datex = qr/\[ # match open square bracket
[FMSTW][a-u]{2} \s # match day of week
[ADFJMNOS][a-y]{2} \s+ # match month
\d+ \s+ \d+:\d{2}:\d{2} \s \d{4} , \s+ # match date
+, time, year
\w+ # match username (could be more explicit)
\]:/x; # match closing bracket, colon
my @text_blocks = split /($datex)/, $textfield;
my $initial_junk = shift @text_blocks unless ( $text_blocks[0] =~ /$da
+tex/ );
my %entry = ( @text_blocks );
print "DATE=> $_ STRING=> $entry{$_}\n" for (keys %entry);
(update: simplified the part that matches the time field)
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.