#!/usr/bin/perl -w use strict; use warnings; use Spreadsheet::WriteExcel; use List::MoreUtils qw( uniq ); open my $line, '<', 'file.log' or die 'Cannot open file'; my $cr_line; my $i = 1; my ($is_an_error_entry,$is_a_warning_entry); my $resolution_link; my (%seen_cr,%seen_match,%seen_link) ; my ($crline,$Buggyfile,$resolutionlink,$match); #subroutine for errors sub error_entry { print "in error entry";#not getting printed my $workbook = Spreadsheet::WriteExcel->new("errors.xls"); my $worksheet = $workbook->addworksheet("Error"); if ($match =~ /Error:/) { $is_an_error_entry = 1; next LINE; } if ($match =~ /https?:/) { if ($is_an_error_entry) { ($resolution_link) = $match =~/(https?:\S+?)[.]?\s/; } } } #subroutine for warnings sub warning_entry { my $workbook = Spreadsheet::WriteExcel->new("warnings.xls"); my $worksheet = $workbook->addworksheet("warnings"); if ($match =~ /Warning:/) { $is_a_warning_entry = 1; } if ($match =~ /https?:/) { if ($is_a_warning_entry) { ($resolution_link) = $match =~/(https?:\S+?)[.]?\s/; } } # ------------------------------------------------------------------------ # MAIN SCRIPT # # ------------------------------------------------------------------------ while ( $match = <$line> ) { if ( $match =~ /CR:/ ) { $cr_line = (split /:\s*/, $match)[1]; chomp $cr_line; $is_an_error_entry = 0; } #need a switch here #1.error entry #2.warning entry print "DEBUG";#no gettting printed error_entry(); warning_entry(); if ( $match =~ /Perforce path:/ ) { if ($is_an_error_entry) { $match = (split /:\s*/, $match)[1]; chomp $match; if ( ($cr_line) and ( !$seen_cr{$cr_line}++ ) ) { $crline = $cr_line; } print $crline, $match, $resolution_link, "\n"; $worksheet->write( $i, 0, $crline ); $worksheet->write( $i, 1, $match ); $worksheet->write( $i, 2, $resolution_link ); $i++; } $cr_line = ''; $crline = ''; $resolution_link = ''; } } }