in reply to parsing multi-line output from a cli command
Here's some (untested) code:
my (@records, $cur_rec); while (<DATA>) { chomp; if (s/^\s+//) { $cur_rec->{'summary'} .= " $_"; next } my ($tick,$cust,$stat,$prio,$owner) = /^ ([\w-]+): \s* # ticket (\[.*?\]) \s* # customer (\[.*?\]) \s* # status (\[.*?\]) \s* # priority (\[.*?\]) # owner /x or next; $cur_rec = { 'ticket#' => $tick, 'customer' => $cust, 'status' => $stat, 'priority' => $prio, 'owner' => $owner, }; push @records, $cur_rec; }
You'll want to do better validation I expect. There are also ways to minimize the redundancy but that's left as an exercise for the reader :-)
|
|---|