next in a for loop?

Eric Schwartz erics at cos.agilent.com
Mon Jun 18 11:02:37 CDT 2001


On Mon, Jun 18, 2001 at 09:33:53AM -0600, Robert L. Harris wrote:
> I have this:
>
>   foreach $i (@content) {
>     next if ($i =~ /^$/);
> 
>     print "\$i :$i:\n";
> 
>   }
> 

<snip>

That works just fine for me.  Here's a transcript:

/home/erics$ perl    
@content  = ('abc', 'def', '', 'fgh', 'ijk');
foreach $i (@content) {
   next if ($i =~ /^$/);

   print "\$i = [$i]\n";
}
^D
$i = [abc]
$i = [def]
$i = [fgh]
$i = [ijk]
/home/erics$ 

> How do I get it to go to the next iteration of the loop if $i is empty?

You could try using a label ("foo: foreach (...) { next foo; }"), I
suppose, but I have a feeling $i may not be as empty as you think it is.
I see you're printing it out with delimiters, so I'm kind of at a loss as 
to what the actual problem might be. :-\

-=Eric
-- 
K is for Kara, had an un-IDd drink
L is for Lana, who fell on a sink
    -- Doug Atkinson <douga at io.com> in rec.games.roguelike.nethack



More information about the Pikes-peak-pm mailing list