in reply to Looping through end of file once a match is found
With print RESULTS <FILE>; because <FILE> will be treated in array context there and grab everything. After that, execution will fall through naturally and when it tries while ($currentfile=<FILE>) { again, it will be at eof so will break out of that loop.do { next LINE; print RESULTS "$currentfile"; } until eof();
And yet another way (take advantage of split), though this involves slurping the log which might be bad if it's large (very untested):my $matchFound = 0; while ($currentfile=<FILE>) { if( ! $matchFound ){ $matchFound = 1 if $currentfile =~ /^\d{6}/ && $search_date eq sub +str($currentfile,52,10); } next unless $matchFound; print RESULTS $currentfile; }
my $currentfile = do { local $/ = undef; <FILE> }; my @parts = split /(^\d{6}).{46}$search_date)/m, $s, 2; print RESULTS @parts[1,2] if $parts[1];
|
|---|