in reply to Two lines Regular Expression

You're only reading one line at a time. Your choices are:

  1. Slurp the entire file into a scalar (such as with my $in = join('', <TMPLFILE>);). This could potentially take a lot of memory
  2. Read in the next line manually ($_ .= <TMPLFILE>;) at the top of your while loop.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Two lines Regular Expression
by Anonymous Monk on Jun 09, 2003 at 19:33 UTC
    Thanks that works now how do I get that match to print outside of the while loop?? I tried something using $data but no luck:
    open(TMPFILE,"<main.html"); while (<TMPFILE>) { chomp; my $data; my $in = join('',<TMPFILE>); if ($in =~ /(myword)\s+nextLine/) { print "Match = " . $1; $data = $1; } } print $data #I want this to print my match results here on myword # so it should print "myword" here but it doesnt.
      It looks like your $data is out of scope. I would recommend use strict; it would have given you an error. Move the my $data; before the the while loop if you want to print afterwards.
        Thanks. Please advise how this catches the next line?
        ($_ .= <TMPLFILE>;)
        what and how does it do that???