http://www.perlmonks.org?node_id=1199658
skumar_pm has asked for the wisdom of the Perl Monks concerning the following question:

I want to split file contents to an outputfile by comparing real number data present in the last line? For example, the file contains of more 100K lines

Start:/abc/def ..... End 1.2 Start:/xyz/uvw ..... End 2.8

I want to print everylines from "Start" to "End" to OUTFILE1 if "End" contains values between 1-1.9; Otherwise print all the lines to OUTFILE2 if "End" contains values between 2-2.9. Likewise, mulitple output files have to be generated.

code here

foreach $lineIn (@file1_list) { $_ = $lineIn; if (/Start:/) { $pattern1 = 1; } elsif(/End\s/) { my @slackno = split /\s+/, $_; $pattern2 = 1; push (@buflines, $_); } if ($pattern1 =~ 1 and $pattern2 =~0) { push (@buflines, $_); } else { $pattern1 = 0; $pattern2 = 0; } } if ($slackno[3] >= 2.0 and $slackno[3] <= 2.9) { foreach ( @buflines ) { print FILE2 $_; } } close(FILE2);

2017-09-20 Athanasius added code tags