Home > Archive > PERL CGI Beginners > January 2005 > Control structures
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Control structures
|
|
| Mark Martin 2005-01-21, 8:55 pm |
| Hi ,
I'm getting as to whether I need a last, next, redo or all of the
above :
foreach $file_item ( @file_items )
{
($file_item_code,$file_item_description)
= split /,/,$file_item ;
$count ++;
$sth->execute($file_item_code);
while ( @fetch = $sth->fetchrow )
{
$database_item_description = $fetch[0];
if ( $file_item_description ne $database_item_description )
{
splice ( @file_items, $count, 1 );
}
}
}
Something will be done with each element of @file_items but only if each
elements description matches the corresponding database elements description.
If there is no match then it should be removed from the array.
This is working but not for adjacent items whose descriptions don't match
their database counterpart.
Is suspect I need some sort of "goto" if a splice occurs.
Mark
| |
|
| On Fri, 21 Jan 2005 18:03:29 -0500, Jay <daggerquill@gmail.com> wrote:
> On Fri, 21 Jan 2005 17:56:17 -0500, Jay <daggerquill@gmail.com> wrote:
>
>
> make that: the first one is left in place, the second one is removed,
> and depending on what the rest of the code looks like, either the
> original match ([$count-1], was [$count]) or the new next item
> ([$count], was [$count+1]) is processed.
>
> --j
>
| |
| Zentara 2005-01-22, 8:55 pm |
| On Fri, 21 Jan 2005 19:20:44 +0000, mark.martin@nuim.ie (Mark Martin)
wrote:
>I'm getting as to whether I need a last, next, redo or all of the
>above :
>
>foreach $file_item ( @file_items )
>{
> ($file_item_code,$file_item_description)
= split /,/,$file_item ;
> $count ++;
>
> $sth->execute($file_item_code);
>
> while ( @fetch = $sth->fetchrow )
> {
> $database_item_description = $fetch[0];
>
> if ( $file_item_description ne $database_item_description )
> {
> splice ( @file_items, $count, 1 );
> }
>
> }
>
>}
>
>Something will be done with each element of @file_items but only if each
>elements description matches the corresponding database elements description.
>If there is no match then it should be removed from the array.
>
>This is working but not for adjacent items whose descriptions don't match
>their database counterpart.
>
>Is suspect I need some sort of "goto" if a splice occurs.
I think Jay answered your problem, but more simply:
I can't quite remember where the docs are, but I think there is a
problem when you try to alter an array while you are iterating thru
it in a loop.
The first thing I would try, is instead of splicing the array, while in
the test loop, I would push the file to be removed into @temp_array,
and do a "next".
Then when you are done with the tests, remove all files in @temp_array
from @file_tests.
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
|
|
|
|
|