in reply to Text Extraction

This should be close to what you require:

#!/usr/bin/perl use strict; use warnings; open TEST, '<', 'tests.txt' or die "Cannot open 'tests.txt' $!"; open OUTPUT, '>', 'output1.txt' or die "Cannot open 'output1.txt' $!"; my $data; while ( <TEST> ) { if ( /SUBSCRIBER/ .. /NATIONAL/ ) { $data .= $_; next; } if ( length $data && $data =~ /A1/ ) { print OUTPUT $data; $data = ''; } } close TEST; close OUTPUT;

Replies are listed 'Best First'.
Re^2: Text Extraction
by JonDepp (Novice) on Feb 05, 2010 at 21:17 UTC

    This works great for the tests.txt file, but whenever I change the input file to something else I get an unitialized value $data in pattern match line 16 error, and I don't know why. Any help is greatly appreciated!!