Hi All
Having been a lurker on this list for some time now (soaking up the
wisdom!), not having needed to use Perl for any projects recently, I
thankfully now have the need to do some good old data munging (quite
refreshing once in a while ;-)) and thought it about time I turned to you
guys for some ideas!
My question is with regards to finding a processor friendly way to delete
multiple (non-sequential) items from an array. I have one array (@one) of
many items (relating to lines in a text file), of which I wish to delete a
certain number based upon a search which stores the item reference in a
temporary array (@two). I then iterate through @two and delete the
corresponding item in @one to the value of the item in @two, with each
iteration reducing the value of the item in @two by the total number of
iterations so as to delete the correct item rather than an item x places
further along than the original.
What I would like to know is there any way to increase the efficiency of my
code, or are there any other ways to accomplish such a task in a more
efficient / optimised manner, through core Perl code or modules etc. (I
have looked and there don't seem to be any to manipulate array in this
way), also there is no reference to any such techniques in any books I have
or any perldoc such as perfaq4. When running the present code over many
thousands of @one items it starts to take an awful long time and causes big
server slowdown, which is a prob as I need to call this from the Web for a
real-time reporting CGI on a internationally busy Web server so there are
no quite periods where I could run a cron without affecting server performance.
many TIA
Ingram
code extracts:
----------
my @two = ();
my @one_split = ();
my $one_line_number = 0;
foreach $n_one(@one) {
@one_split = split(/::/, $n_one);
if ($one_split[0] =~ /some_test/) {
push (@two, $one_line_number);
}
$one_line_number++;
}
my $two_rep_number = 0;
foreach $n_two(@two) {
splice (@one, ($n_two- $two_rep_number), 1);
$two_rep_number++;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]