If the log file is huge, it will be better to avoid the scalar variable altogether and to instead read the file in backwards, line by line. The File::ReadBackwards module on is designed for this purpose:
#! perl use strict; use warnings; use File::ReadBackwards; my $logfile = 'log.txt'; my $header = 'start: real'; my $footer = 'end: real'; my $in_data = 0; my @lines; my $bw = File::ReadBackwards->new($logfile) or die "Cannot open file '$logfile' for reading backwards: $!"; while (my $line = $bw->readline) { chomp $line; if ($in_data) { unshift @lines, $line; last if $line eq $header; } elsif ($line eq $footer) { unshift @lines, $line; $in_data = 1; } } print join("\n", @lines), "\n";
No regex needed. :-)
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^2: Regex to find the last matching set in a long scalar
by Athanasius
in thread Regex to find the last matching set in a long scalar
by superwombat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |