Ohh,
Thanks for the help
On Mon, Nov 2, 2009 at 1:40 PM, John W. Krahn <[email protected]> wrote:
> Anant Gupta wrote:
>
>> Hello,
>>
>
> 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(......)
>> {
>> }
>> }
>>
>
> You should use readline() in a while loop instead of a foreach loop:
>
> use warnings;
> use strict;
>
> open FILE, '<', 'abc.txt' or die "Cannot open 'abc.txt' $!";
>
> while ( my $line = <FILE> )
> {
> if ( $line =~ /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
>
> $next_line = <FILE>;
>
> }
> if(......)
> {
> }
> }
>
>
>
> John
> --
> The programmer is fighting against the two most
> destructive forces in the universe: entropy and
> human stupidity. -- Damian Conway
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>