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.
In reply to Re: Data parsing - takes too long
by ptum
in thread Data parsing - takes too long
by josephjohn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |