in reply to How to 'peek' at next line while parsing with <>

Depending on the size of the input file, you could
  1. Read the file into an array if the file is not too large; or
  2. Arrange to pretend that the current line from the diamond operator is the 'next' line and the last line is the 'current' line.

--t. alex

"Mud, mud, glorious mud. Nothing quite like it for cooling the blood!" --Michael Flanders and Donald Swann

  • Comment on Re: How to 'peek' at next line while parsing with <>

Replies are listed 'Best First'.
Re: Re: How to 'peek' at next line while parsing with <>
by DamnDirtyApe (Curate) on Jul 11, 2002 at 17:08 UTC

    Number two was also what I had in mind. Something like the following:

    #! /usr/bin/perl use strict ; use warnings ; my $line = <> ; my $queued_line = '' ; chomp $line ; while ( $queued_line = <> ) { chomp $queued_line ; $line =~ m|<(.+?)>| ; print "Found match: [$1] (next line: $queued_line)\n" ; $line = $queued_line ; } $line =~ m|<(.+?)>| ; print "Found match: [$1] (last line)\n" ;

    _______________
    D a m n D i r t y A p e
    Home Node | Email