Frank <mailto:[EMAIL PROTECTED]> wrote: : The results given like this, it seems the loop works only for one time : : >common_white : paper : >milk_white : milk
This is what you asked perl to do. Let's walk the script. First time through $item is ">blue". Since $after_white tests false, this is what happens (nothing). foreach my $item ( @items ) { $after_white = 1 if $item =~ /white$/; if ( $after_white ) { } } Next time through $item is "sky". Since $after_white tests false, this is what happens (nothing). foreach my $item ( @items ) { $after_white = 1 if $item =~ /white$/; if ( $after_white ) { } } Next time through $item is "skirt". Since $after_white tests false, this is what happens (nothing). foreach my $item ( @items ) { $after_white = 1 if $item =~ /white$/; if ( $after_white ) { } } Next time through $item is "sea". Since $after_white tests false, this is what happens (nothing). foreach my $item ( @items ) { $after_white = 1 if $item =~ /white$/; if ( $after_white ) { } } Next time through $item is ">common_white". Since both $after_white and "$item =~ /^>/" test true, this is what happens. foreach my $item ( @items ) { $after_white = 1 if $item =~ /white$/; if ( $after_white ) { print "$item\n"; next if $item =~ /^>/; } } Next time through $item is "paper". Since $after_white tests true, but "$item =~ /^>/" tests false, this is what happens. Note that $after_white will test false after this. foreach my $item ( @items ) { $after_white = 1 if $item =~ /white$/; if ( $after_white ) { print "$item\n"; next if $item =~ /^>/; $after_white = undef; } } Next time through $item is "flower". Since $after_white tests false, this is what happens (nothing). foreach my $item ( @items ) { $after_white = 1 if $item =~ /white$/; if ( $after_white ) { } } Do you see the error now? You told perl to stop after the second line was printed. You didn't give a stopping point like you did last time. You need a small ego to be a computer programmer. You are very unlikely to run into a perl bug. Assume every problem you have as your own fault. This often means stepping through a script one line at a time to find your error. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>