mysticp...@yahoo.com wrote: > How to validate input data from file, > the below simple code ,matches without the END block , > > How to solve this input ,such that only those records with END block > are matched ? > > Data::Domain or Parse::RecDescent ? > > > > open(IN,"inputdatafile") > while(<IN>){ > if(/^BEGIN/ .. /^END/){ > add content to hash > } > else { > do something else > } > } > > INPUTDATAFILE > ============================= > BEGIN > begindata1set > data1 data2 data3 > datax datay dataz > enddata1set > begindata2set > data1 data2 data3 > datax datay dataz > enddata2set > END > BEGIN > begindata1set > data1 data2 data3 > BEGIN > begindata1set > data1 data2 data3 > datax datay dataz > enddata1set > begindata2set > data1 data2 data3 > datax datay dataz > enddata2set > END
The program below should help you. Rob use strict; use warnings; open my $in, '<', 'inputdatafile' or die $!; my @record; while (<$in>) { chomp; if (/^BEGIN/) { @record = ($_); } elsif (@record) { push @record, $_; } if (/^END/) { print "$_\n" foreach @record; @record = (); } } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/