in reply to Extracting Lines of a text file

hi,

i don't know if this helps but you could play around with regex and do some thing like this :

use strict; print"Please type the term you're looking for\n"; chomp (my $cho = <STDIN>); open (FILE, "<", $ARGV[0]) || die "$!"; $/ ="(.*)\n(.*)\n(.*)"; while (<FILE>){ m/(.*)\n(.*)\n(.*)/gi; next if (!m/(.*)\n$cho\n(.*)/ ); print "$1\n$cho\n$2"; } $/ = "\n";
it does exactly this:

fff aaa aaa bbb => bbb ccc ccc ddd
there are many ways to do it ! but it depends if this is what you actually need. here i've just changed the recognition pattern (input record separator) from \n (which is standard) to stuff\nyour_stuff\nstuff and then evaluate the middle pattern to your pattern. read more about $/ here.

Replies are listed 'Best First'.
Re^2: Extracting Lines of a text file
by ikegami (Patriarch) on Nov 04, 2008 at 10:35 UTC

    That doesn't work like you think it does. You should head your own advice and read the docs for $/. $/ is treated as a string, not a regexp pattern. Try it with the file

    fff aaa bbb ccc ddd fff aaa bbb ccc ddd