in reply to restricting matching only to consecutive lines

Had a bit of fun with this. I'm sure there is a much shorter and better way, but alas, it is what it is :) Using your data:

#!/usr/bin/perl use warnings; use strict; my @hold; my @data; while ( my $line = <DATA> ){ chomp $line; if ( $line =~ /NIL$/ || $line !~ /\w+/ ){ if ( scalar @hold > 1 ){ push @data, [ @hold ]; } undef @hold; next; } push @hold, $line; } for my $block ( @data ){ for my $entry ( @{ $block } ){ print "$entry\n"; } print "\n"; }

EDIT: Fixed code so it would work with more than two consecutive lines.

Replies are listed 'Best First'.
Re^2: restricting matching only to consecutive lines
by anasuya (Novice) on Mar 26, 2012 at 09:25 UTC

    Thanks, stevieb.