Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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?
Discipulus dscivered BASH supports also double quotes..
choroba recommends ABSG to Discipulus
[erix]: yes, very handy that. I always use the one-page html version (dumped a local copy of it)

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2017-11-24 11:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (348 votes). Check out past polls.

    Notices?