On Mon, 02 Nov 2009 13:06:27 +0530, Anant Gupta wrote: > Hello, > > In the foreach loop, without going to the beginning of the loop, i want > to get the next iteration of data. How do i get it. eg > > use strict; > open(FILE,"<abc.txt") or die "CAnnot open"; my @lines=<FILE>; > foreach my $line(@lines) > { > if($lin =~ m/something/) > { > #some code > # get next data > # Without going to the beginning of the loop i want to see the > next > data "$line" > # using "next;" takes me to the beginning # is their any > command or i will have to use flags > } > if(......) > { > } > }
Whether it's a while loop or a foreach loop, whenever I find myself wanting to do what you're asking about (iterate from a midpoint in the loop), I rewrite the code so it doesn't, unless it's some tiny one-off. I hate what that does to the topology of my program and how much harder it makes it to read. In an application like this one, it generally signifies that I should be parsing the whole file as a single string, or reading it in in larger chunks than a single line. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ http://www.informit.com/store/product.aspx?isbn=0137001274 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/