http://www.perlmonks.org?node_id=1005489


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

Hi, thanks for your reply.

I am trying to match from the DATA handle.

  • Comment on Re^2: How to print the lines immediately above and below a matching line?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to print the lines immediately above and below a matching line?
by toolic (Bishop) on Nov 25, 2012 at 13:41 UTC
    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>;?

        Show that code? Where did you add the line?

Re^3: How to print the lines immediately above and below a matching line?
by Anonymous Monk on Nov 25, 2012 at 13:40 UTC
    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.

        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.

        Right, and you're merely trying to write a perl program -- might as well learn the basics of the syntax, like what goes in a match operator is not an attempt to read from a filehandle -- you have to separate the steps

        Are you sure an already written perl program, say something from the bioperl.org website wasn't suggested instead?