Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to print the lines immediately above and below a matching line?

by toolic (Bishop)
on Nov 25, 2012 at 13:23 UTC ( [id://1005487]=note: print w/replies, xml ) Need Help??


in reply to How to print the lines immediately above and below a matching line?

if ($this_line =~ /<DATA>/) {
Are you trying to read from the special DATA handle, or are you trying to match the exact string <DATA>? re indicates you are doing the latter:
perl -Mre=debug mycode.pl Compiling REx "<DATA>" Final program: 1: EXACT <<DATA>> (4) 4: END (0) anchored "<DATA>" at 0 (checking anchored isall) minlen 6 Error opening file - No such file or directory Freeing REx: "<DATA>"

Replies are listed 'Best First'.
Re^2: How to print the lines immediately above and below a matching line?
by Bio90 (Initiate) on Nov 25, 2012 at 13:36 UTC
    Hi, thanks for your reply.

    I am trying to match from the DATA handle.

      Then you need to change your code. Something like:
      my $data = <DATA>; chomp $data; if ($this_line =~ /\Q$data/)
        I have tried that but it has returned a "Use of uninitialised value $data". I do not understand - surely $data is initialised by my $data = <DATA>;?
      Maybe you should read a line from that handle instead ... don't skip the basics, read perlintro
        I'm sorry, I am a Biology student and I have merely had perl suggested to me as a means to an end in order to get my data into a usable format.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-24 19:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found