http://www.perlmonks.org?node_id=1058115


in reply to Re^2: How to extract certain range of text and display it?
in thread How to extract certain range of text and write into another file?

I can't figure out what variable should I match the section text.

post the new code

  • Comment on Re^3: How to extract certain range of text and display it?

Replies are listed 'Best First'.
Re^4: How to extract certain range of text and display it?
by annel (Novice) on Oct 14, 2013 at 02:05 UTC
    Here is the code I updated. Please check it. Thanks.
    use warnings; use strict; my $test; my @words; open(INFO,"<","testing.pl")||die"Can't open file:$!\n"; chomp (@words=<INFO>); close(INFO); foreach @words){ if(/^\$ NAME : corry/ .. /\.EON/){ $test=$1; print $test; } }

      well, you're using $1 without using capture groups which moritz told you about , and which perlintro talks about ($1)

      why are you using $1, maybe you want to use $_?

        use warnings; use strict; my $test; my @words; open(INFO,"<","testing.pl")||die"Can't open file:$!\n"; chomp (@words=<INFO>); close(INFO); foreach (@words){ if(/^\$ NAME : corry/ .. /\.EON/){ $test=$_; print $test; } }
        I used $_ but nothing prints out.