Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by toolic (Chancellor)
on Nov 25, 2012 at 13:23 UTC ( #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>"


Comment on Re: How to print the lines immediately above and below a matching line?
Select or Download Code
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.

      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.
      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>;?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-09-19 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (144 votes), past polls