A more basic example

use warnings; use strict; #my $testout=`$test list`; my $testout=' CoID: Type: State: ID: ExampleCo A former 97546 ExampleCo B pending 48541 ExampleCo A ready 75521 ExampleCo B former 50123 ExampleCo A contact 60047 ExampleCo B contact 19425 '; my @order; my $array={}; my @sparse; my @compact; for my $l (split("\n",$testout)) { chomp $l; my ($coid,$type,$state,$id)=split(' ',$l,4); next unless ($type eq 'A'); my $h={ID=>$id,CoID=>$coid,State=>$state}; push @order,$id; $array->{$id}=$h; $sparse[$id]=$h; push @compact,$h; } print 'From hash'."\n"; for my $o (@order) { my $h=$array->{$o}; print ' ID = '.$h->{ID}."\n"; print ' CoID = '.$h->{CoID}."\n"; print ' State = '.$h->{State}."\n"; } print 'iterate compact'."\n"; for my $h (@compact) { next unless (defined $h); print ' ID = '.$h->{ID}."\n"; print ' CoID = '.$h->{CoID}."\n"; print ' State = '.$h->{State}."\n"; } print 'index sparse'."\n"; for my $o (@order) { my $h=$sparse[$o]; print ' ID = '.$h->{ID}."\n"; print ' CoID = '.$h->{CoID}."\n"; print ' State = '.$h->{State}."\n"; }
result
From hash ID = 97546 CoID = ExampleCo State = former ID = 75521 CoID = ExampleCo State = ready ID = 60047 CoID = ExampleCo State = contact iterate compact ID = 97546 CoID = ExampleCo State = former ID = 75521 CoID = ExampleCo State = ready ID = 60047 CoID = ExampleCo State = contact index sparse ID = 97546 CoID = ExampleCo State = former ID = 75521 CoID = ExampleCo State = ready ID = 60047 CoID = ExampleCo State = contact
This example does not need IPC::System::Simple to be preinstalled, uses the `$test` call format that you implied, captures only the type=a records, and shows it stored in a hash, compact array and sparse array, iterating over the compact array and indexing the sparse array.

if you prefer to install IPC::System::Simple that is a much prettier program (edit:) and you add the test for type=a


In reply to Re: Parsing output from a 'system' call into objects? by huck
in thread Parsing output from a 'system' call into objects? by eval142

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.