I totally agree with kvale (++) -- highest preference to using Text::xSV on this problem. And just in case you'd like to look at an alternative approach (just as an educational exercise), consider this:
$_ = 'Jul 15 15:12:10 a=foo time="2004-07-14 01:20:25 UTC" b=abc@foo.c
+om msg="^one can say anything here except quotes$"';
my ($timestamp,%pairs) = split(/\s+(\w+)=/);
print "Timestamp => $timestamp\n";
print "$_ => $pairs{$_}\n" for (sort keys %pairs);
__OUTPUT__
Timestamp => Jul 15 15:12:10
a => foo
b => abc@foo.com
msg => "^one can say anything here except quotes$"
time => "2004-07-14 01:20:25 UTC"
The magic is in using split with a capturing regex, which will divide up the string into its component values, while keeping (and passing along) the attribute titles as well.
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.