viffer has asked for the wisdom of the Perl Monks concerning the following question:
I know this isn't something that is normally done, but I seriously can't think of any other way to process the file I'm looking at
I have a hash containing a number of keys, and an array that contains a number of records.
For each hash key I'm processing all the records in the array, and printing off the records in the array that have a field that matches the hash key.
The problem I have, is that for each hash key I process, I'm reading the entire array EVERY time. Once I've printed the records in the array I want to delete them so they they don't get processed every single time.
For 40,000 records the process is taking in excess of 3 hours.
I think I can delete the record from the array if I know what the index of the record is, but I'm not sure how to work that out
What I'm trying to do is to find a way to delete the record from the array when I've processed it, so that I'm not processing a record I've already processed once before.for my $key (keys %coll_key_hash) { foreach my $rec (@recs_read) { my @fields = split(/\|/, $rec); if ($fields[0] eq '010') { if ($fields[3] =~ $key) { $print_record = 1; if ($key ne $prev_key) { $prev_key = $key; print_record ("CUST-BEG|$seq\n",' '); } print_record ("$rec\n",'c'); } else { $print_record = 0; } } else { if ($print_record) { print_record ("$rec\n",'c'); } } } }
Any suggestions gratefully received. Thanks - and Merry Xmas to all
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Deleting records from an array
by Anonymous Monk on Dec 22, 2014 at 08:34 UTC | |
by Anonymous Monk on Dec 22, 2014 at 08:37 UTC | |
by Anonymous Monk on Dec 22, 2014 at 08:40 UTC | |
|
Re: Deleting records from an array
by igoryonya (Pilgrim) on Dec 22, 2014 at 12:29 UTC | |
by Anonymous Monk on Dec 22, 2014 at 14:10 UTC | |
|
Re: Deleting records from an array
by Lotus1 (Vicar) on Dec 22, 2014 at 14:20 UTC | |
|
Re: Deleting records from an array
by Anonymous Monk on Dec 22, 2014 at 21:29 UTC |