in reply to Re: Re: Two lines Regular Expression
in thread Two lines Regular Expression

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.

Replies are listed 'Best First'.
Re: Re: Re: Re: Two lines Regular Expression
by Anonymous Monk on Jun 09, 2003 at 22:52 UTC
    Thanks. Please advise how this catches the next line?
    ($_ .= <TMPLFILE>;)
    what and how does it do that???

      It works by concatenating (with ".") the contents of $_ (your current line in this case) with the last line(s) read in. It is equivalent to: $_ = $_ . <YOURFILE>. You can have a look at perldoc perlop under "Assignment Operators" for a more detailed explanation.

      If you have:

      line one line two line three

      the first time around, $_ is "line one\n", the second time around, $_ becomes "line one\nline two\n", and the third time around, $_ becomes "line one\nline two\nline three\n", which allows you to use your regex across more than one line in the file.

      --
      Allolex

      That just uses a special kind of string concatanation operator to append the input. It's equvilent to $_ = $_ . <TMPLFILE>;

      ----
      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