So your summary comes second, and can be multiline. Hmm. Anyway, what distinguishes between the first and the next lines, is the leading whitespace on the latter.

What I'd do is something like the following — which doesn't quite work according to your minimal spec, but is better, IMHO:

my(@records, $ref); while(<DATA>) { chomp; if(my @fields = /^(\S+): \[(.+?)\] \[(.+?)\] \[(.+?)\] \[(.+?)\]\s +*$/) { my %record; @record{'ticket#', qw(customer status priority owner)} = @fiel +ds; push @records, $ref = \%record; } elsif(s/^\s+//) { if(defined $ref->{summary}) { $ref->{summary} .= "\n$_"; } else { $ref->{summary} = $_; } } else { warn "Oops: no match in: $_\n"; } } use Data::Dumper; print Dumper \@records; __DATA__ fabx-t160: [ggurudut] [UNAN/OWNR] [C2] [kelrod] navicli chglun -l 3 -name "newname" doesn't work fabx-t161: [dozone] [UNAN/OWNR] [C2] [dchoi] The GUI needs to hide the CPP SEs from the unimported list fabx-t162: [haurora] [UNAN/OWNR] [C1] [glade] Cisco hardware related bug :idprom error on cisco switch on loading + 0.1.5.5 salagent (This line won't match)
which produces the output (the first line is a warning, which goes to STDERR):
Oops: no match in: (This line won't match) $VAR1 = [ { 'summary' => 'navicli chglun -l 3 -name "newname" doesn\'t + work', 'status' => 'UNAN/OWNR', 'customer' => 'ggurudut', 'ticket#' => 'fabx-t160', 'owner' => 'kelrod', 'priority' => 'C2' }, { 'summary' => 'The GUI needs to hide the CPP SEs from the u +nimported list', 'status' => 'UNAN/OWNR', 'customer' => 'dozone', 'ticket#' => 'fabx-t161', 'owner' => 'dchoi', 'priority' => 'C2' }, { 'summary' => 'Cisco hardware related bug :idprom error on +cisco switch on loading 0.1.5.5 salagent', 'status' => 'UNAN/OWNR', 'customer' => 'haurora', 'ticket#' => 'fabx-t162', 'owner' => 'glade', 'priority' => 'C1' } ];

Perhaps a tiny bit of explanation is in order. When the first line of a record is encountered, a fresh hash ref, a new record holding the data for the first line, is pushed onto the global memory array @records. At the same time, a reference to this latest record is kept in the variable $ref. We can use that ref to still modify the original record, even while it's already on the array. So I use it to append more summary lines to the hash item for 'summary'.


In reply to Re: parsing multi-line output from a cli command by bart
in thread parsing multi-line output from a cli command by TASdvlper

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.