This captures the data in the format you want:

$ perl -Mstrict -Mwarnings -E ' use constant { ACTION => 0, FAN_A => 1, FAN_B => 2, SEND => 3, FAILURE => 4, }; my $re = qr{ \A \d+ \s+ (?<date> \S+ ) .*? ACTION=< (?<ACTION> [^>]+ ) > \s+ FAN_A=< (?<FAN_A> [^>]+ ) > \s+ FAN_B=< (?<FAN_B> [^>]+ ) > \s+ SEND=< (?<SEND> [^>]+ ) > \s+ FAILURE=< (?<FAILURE> [^>]+ ) }x; my $log_line = q{19476 2013-04-05,12:10:51.909293 host:internal.ma +chine44.company.net main INFO Running normally with ACTION=<processin +g> FAN_A=<OK> FAN_B=<OK> SEND=<Sent mail (221 2.0.0 Service closing t +ransmission channel)> FAILURE=<2>}; $log_line =~ /$re/; my ($date, @info) = @+{qw{date ACTION FAN_A FAN_B SEND FAILURE}}; say $date; say $info[ACTION]; say $info[FAN_A]; say $info[FAN_B]; say $info[SEND]; say $info[FAILURE]; ' 2013-04-05,12:10:51.909293 processing OK OK Sent mail (221 2.0.0 Service closing transmission channel) 2

This is just a commandline proof-of-concept. Your real-world application would probably look more like:

... use constant { ... my $re = qr{ ... open my $log_fh, '<', $logfile or die $!; while my $log_line (<$log_fh>) { $log_line =~ /$re/; my ($date, @info) = @+{qw{date ACTION FAN_A FAN_B SEND FAILURE}}; # do something with $date and @info here }

See perlre - Extended Patterns for details of Named Capture Groups: (?<NAME>pattern)

-- Ken


In reply to Re: Some assistance with splitting variables by kcott
in thread Some assistance with splitting variables by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.