Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by annel (Novice)
on Oct 14, 2013 at 01:43 UTC ( #1058114=note: print w/ replies, xml ) Need Help??


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

Hi, thanks for your response. I did it as following but nothing display of the output.

use warnings; use strict; my $test; my @words; open(INFO,"<","testing.pl")||die"Can't open file:$!\n"; chomp (@words=<INFO>); close(INFO); local $/ = ".EOM\n\n"; while ( my $record = @words) { print $record; }
Where did I make mistake?


Comment on Re^2: How to extract certain range of text and display it?
Download Code
Replies are listed 'Best First'.
Re^3: How to extract certain range of text and display it?
by soonix (Vicar) on Oct 14, 2013 at 08:45 UTC
    CountZero's advice is more than just "setting $/". You have to
    1. define $/ before reading your file
    2. of course, spell your record separator correctly, as noted by jakeease
    3. change your logic accordingly, because a "record" now contains multiple lines (those belonging to one name)
      Thanks for your response. I have updated my code and question. Can you give me some idea where to define $/?
        For example, I need to extract the $ NAME: sandy until $$.TO and then join with the contents inside $NAME: patrick which is start from G1 until $$SRU.
        Your sample data seems to indicate that the data for each name starts with "$ NAME" and ends with a line ".EON", which is the base of our suggestions until now. The quoted sentence seems to indicate something different. So you should clarify:
        • how do you recognize which line belongs to which name (via $ NAME and .EON, or different)?
        • how do you determine which part of those lines for a particular name you are interested in?
        • [Update: additional question] do you need to preserve the order of these entries/lines?
        Um, why not simply "copy/paste" what others have posted? Up above?
Re^3: How to extract certain range of text and display it?
by jakeease (Friar) on Oct 14, 2013 at 07:21 UTC

    CountZero's suggestion is

    local $/ = ".EON\n\n";

    you simply have a typo:".EOM...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058114]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2015-07-29 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls