Joshua Kaufman wrote:
>
> Hi All;
Hello,
> I'm trying to match a pattern in a text file and then print out the next
> line in that file. I could swear that I've done this before by incrementing
> $. to move to the next line. However, the code below is printing out the
> matched line rather than the next line.
>
> #!/usr/bin/perl
>
> open (LOG, "./lmelog");
>
> for ( <LOG> ) {
> if ( /- Student Id/){
> ++$.;
> print "$_\n";
>
> }
> }
>
> I really don't want to save the file into an array,
If this is your actual code then you are doing something as bad by
slurping the entire file into a list.
> given that it is > 10^6 lines long.
You need to read the next line from the file handle.
while ( <LOG> ) {
if ( /- Student Id/ ){
$_ = <LOG>;
print "$_\n";
}
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]