I'm late to this party, as usual, but since the OP mentioned "Objects" - here is a working OO version:
use strict; use warnings; BEGIN{ package Company; my (%by_id, %by_type); sub new{ my ($class,$coid,$type,$state,$id) = @_; my $self = bless {COID=>$coid,TYPE=>$type,STATE=>$state,ID=>$id}, + $class; $by_id{$id} = $self; push @{$by_type{$type}}, $self; return $self; } sub All_ID_callback{ # Class method my ($callback) = @_; for (sort keys %by_id){ $callback->($by_id{$_}, $_); } } sub get_id{ # CLASS method my ($id) = @_; return $by_id{$id}; } sub for_each_bytype_callback{ # CLASS method my ($type, $callback) = @_; for my $o (@{$by_type{$type}}){ $callback->($o); } } sub PRINT{ my ($self, $header) = @_; $header and print "$header\n"; print ' ID = ', $self->{ID}."\n"; print ' CoID = ', $self->{COID}."\n"; print ' State = ', $self->{STATE}."\n"; } } #--- Main ---- #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 '; for my $l (split("\n",$testout)) { chomp $l; my $company = Company::->new(split(' ',$l,4)); } print "---In ID sequence---\n"; Company::All_ID_callback( ## In ID sequence sub{ my $o=shift; return unless $o->{TYPE} eq "A"; $o->PRINT(); }); print "---Selecting by type---\n"; Company::for_each_bytype_callback("A", sub{my $o=shift; $o->PRINT(); } );

        ...it is unhealthy to remain near things that are in the process of blowing up.     man page for WARP, by Larry Wall


In reply to Re: Parsing output from a 'system' call into objects? by NetWallah
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.