Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - # Find time gaps in a joblog, sorting by time differences between successive records
 - # Entries of the Job Log are of the form
 - #
 - # |15.12.2020|04:07:17|Datei ATRON_STAMMDATEN.CSV enthΓ€lt 720 Fehler; folgende "Arten" (Alle=ZAFM_LIEF_STAT1): | ZAFM | 156 | S |
 - # |15.12.2020|04:07:17|720 Fehler mit ZAFM-011: Doppelter GTIN & bei Lieferant & Zeilennummer &. | ZAFM | 157 | S |
 - # |15.12.2020|04:47:22|Insgesamt wurden 158757 Zeilen abgespeichert aus Datei ATRON_STAMMDATEN.CSV. | ZAFM | 009 | S |
 - #
 - # Log lines which don't start with date and time like these are ignored
 - use DateTime;
 - use constant {
 - # Constant filename:
 - # Use fixed filename, or $ARGV[0] from the command line
 - JOBLOG_FILENAME => $ARGV[0] || "C:\\Temp\\joblog.txt",
 - # Show only the top 20 time gap entries:
 - TOP => $ARGV[1] || 20,
 - # Change the regex DATE_TIME_PATTERN to catch the date and time for different log formats:
 - DATE_TIME_PATTERN => qr/^\|(\d{2})\.(\d{2})\.(\d{4})\|(\d{2}):(\d{2}):(\d{2})/
 - };
 - open JOBLOG, "<", JOBLOG_FILENAME or die "Can't open ${ \JOBLOG_FILENAME }: $!\n";
 - my @log = ();
 - my $last_time = 0;
 - foreach my $line ( <JOBLOG> ) {
 - next unless my @dt = ( $line =~ DATE_TIME_PATTERN );
 - my $this_time = new DateTime(
 - day => $dt[0],
 - month => $dt[1],
 - year => $dt[2],
 - hour => $dt[3],
 - minute => $dt[4],
 - second => $dt[5]
 - );
 - if ($last_time) {
 - push @log, [ $this_time->epoch - $last_time->epoch, $line ];
 - }
 - $last_time = $this_time;
 - }
 - # In Perl, "@a = sort @a" sorts @a inplace internally (no copying):
 - @log = sort { $b->[0] <=> $a->[0] } @log;
 - foreach $a (@log[0..TOP-1]) {
 - printf( "%5d %s", $a->[0], $a->[1] );
 - }
 - close JOBLOG;
 
                    Add Comment                
                
                        Please, Sign In to add comment