in reply to Returning Line where Characters Have been found

Two ways to do it:

use strict; use warnings; my $cmdout = join '', <DATA>; while ($cmdout =~ /^(.*?lines.*?)$/mg) { print "$1\n"; } my @cmdout = split /\n/, $cmdout; for (@cmdout) { print "$_\n" if m/lines/; } __DATA__ my multiple lines of data go here and here are some more lines of data

Replies are listed 'Best First'.
Re^2: Returning Line where Characters Have been found
by apraxas (Initiate) on Dec 13, 2011 at 15:00 UTC
    Hi TJ, thanks for your ideas here, but sadly i am a bit too stupid to understand what you have written there, i a struggling with the < DATA > part ..

      The __DATA__ segment at the end of the file stores data in what Perl interpretes as some sort of pseudo-file. To read that out, you can use the filehandle DATA.

      What TJPride does here is reading out all the lines as array and joining them into a single string. (Reading from < DATA > in array context since it is the array argument to join).

      BREW /very/strong/coffee HTTP/1.1
      Host: goodmorning.example.com
      
      418 I'm a teapot
      my $cmdout = join '', <DATA>; is the same as if I just put all the stuff below the __DATA__ line into $cmdout directly. It's also the same as if I had that data in a file, opened a filehandle to it (let's say FH) and then read it using my $cmdout = join '', <FH>;. Basically, __DATA__ is just a good way to post code examples without having to exclude the file data it's running on.