next in a for loop?

Robert L. Harris Robert.L.Harris at rdlg.net
Mon Jun 18 11:06:45 CDT 2001



I found a work around but I tried "next if ($i eq "");" and "next if ($i =~ /%$/);"
quite a few times and it still ran.

Robert

Thus spake Eric Schwartz (erics at cos.agilent.com):

> 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



:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'




More information about the Pikes-peak-pm mailing list