in reply to how to extract certain lines

here is what im try to type
example
HERE IS THE DATA
PLACED ABC;
DO NOT ENTER
PLACED BCD;
HERE IS THE DATA
PLACED ABC;
WHO ARE U
PLACED ABC;
I want to extract the lines started with "PLACED..
if the line "HERE IS THE DATA appear before it

Replies are listed 'Best First'.
Re^2: how to extract certain lines
by neilh (Pilgrim) on Oct 26, 2004 at 04:29 UTC
    Try this

    while (<DATA>) { next unless /^HERE IS THE DATA/; my $line = <DATA>; print $line; } __DATA__ HERE IS THE DATA PLACED ABC; DO NOT ENTER PLACED BCD; HERE IS THE DATA PLACED ABC; WHO ARE U PLACED ABC; __OUTPUT__ PLACED ABC; PLACED ABC;

    Neil

      Thank you Neil..
      I still have questions here.
      Why do you use my before $line
      what is the function of my here?
      Thank you
        Hi dee00zee,
        The my puts the variable into scope within the while loop.
        For information have a look at perldoc perlintro and the discussion on lexical scope.

        Neil

        my is used to declare and assign the variable $line. If you would 'use strict;' this is a requirement for the script to run.

        Manual for my: http://www.perl.com/doc/manual/html/pod/perlfunc/my.html

        Edit: Excuse me for this post, I somehow missed that the question was already answered.