Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How to extract certain range of text and display it?

by moritz (Cardinal)
on Oct 13, 2013 at 11:09 UTC ( #1058059=note: print w/replies, xml ) Need Help??


in reply to How to extract certain range of text and write into another file?

Your most obvious problem is that there is no occurrence of Corry in the test data, only corry. And no, the two are not the same.

Another problem is that you use $1, but the regex before it doesn't use a capturing group that could fill $1.

A third problem is that the iteration variable is $word, but the regexes match against $_, thus have no chance to succeed. I'm pretty sure you get an uninitialized... warning from that. Didn't you? Or did you just ignore it? (hint: never ignore the warning).

Replies are listed 'Best First'.
Re^2: How to extract certain range of text and display it?
by annel (Novice) on Oct 14, 2013 at 01:30 UTC
    Hi, the problems you have mentioned are totally correct. I have correct the occurrence of  corry and get rid of $word. I can't figure out what variable should I match the section text.

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

      post the new code

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058059]
help
Chatterbox?
and the shadows deepen...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2017-09-23 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (272 votes). Check out past polls.

    Notices?