It seems to me that this problem cries out for an associative array (hash). Try splitting your inventory file and storing the array of elements you need in a lookup hash (keyed by the first token). Then when you split your client file, you can check to see if a hash entry matching the 4th token exists, and if so, grab the necessary element array from that hash entry. You can use delete() to get rid of unwanted hash entries once you're done with them.

Update: Added (untested) code sample:

my %inventory_hash = (); open DataFile, "Inventory.csv" or die ("Inventory.csv $!"); while (my $inventory_line = <DataFile>) { my @inventory_fields = split /,/,$inventory_line; my $inventory_key = shift @inventory_fields; if (exists($inventory_hash{$inventory_key})) { print "Warning! Duplicate inventory key detected: $inventory_key\n +"; next; } $inventory_hash{$inventory_key} = \@inventory_fields; } close DataFile; open DataFile, "clients.txt" or die ("clients.txt $!"); while (my $line = <DataFile>) { my @fields = split(/,/, $line); if (exists($inventory_hash{$fields[3]})) { my @sys = @{$inventory_hash{$fields[3]}}; # do stuff with the contents of @sys, print, whatever delete $inventory_hash{$fields[3]}; } }

Hope this rather abbreviated example helps.


No good deed goes unpunished. -- (attributed to) Oscar Wilde

In reply to Re: Data parsing - takes too long by ptum
in thread Data parsing - takes too long by josephjohn

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.