http://qs321.pair.com?node_id=731445


in reply to Using grep to pick out lines in a text file

You're reading the whole file into an array, which you don't need to do, if the entries are on different lines. Just read the document line by line.

I'd also say you're muddled about arrays: for each item in the array, you grep through each item in the array!

This is how I'd do it:

use strict; use warnings; open( INPUTFILE, "<WordNet.txt" ) or die "$!"; open( OUTPUTFILE, ">>WordNetTest2.txt" ) or die "$!"; print "Extracting adjectives\n"; my $previous_line; while (<INPUTFILE>) { if ( $_ =~ m/^Adj:/ ) { print OUTPUTFILE $previous_line, $_; print "found one!\n"; } $previous_line = $_; }


Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...