> On Mar 26, 2017, at 1:20 AM, X Dungeness <dery...@gmail.com> wrote:
> 
> but you could post-process the logfile in an END {} block

        I wouldn't have thought of that.  Thanks!

        This now gives me a cleaner log to scan — streamlining the timestamp 
and adding a blank line between entries.  I also learned about $^I / 
$INPLACE_EDIT.  Very nice!

http://perldoc.perl.org/perlvar.html#SPECIAL-VARIABLES


END {
    use Time::Piece;
    $^I = '';
    @ARGV = '/path/to/error.log';
    while (<>) {
        next if (m/^\s*$/);
        if (m/\[(.+)\](.+)/) {
            my ($timestamp, $message) = ($1, $2);
            ## [Wed Mar 22 12:43:20 2017] -- Original timestamp format.
            my $dt = Time::Piece->strptime($timestamp, '%a %b %d %H:%M:%S %Y');
            my $datetime = $dt->strftime('%Y-%m-%d %H:%M');
            say "[$datetime] $message\n";
        }
        else {
            say;
        }
    }
}
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to