Thanks ken!
I tested the above suggestion by you. Below is the whole code:
@file = glob "$dir/MyAccount_OneTimePay_BaseLine.usr/Action.c";
my $row = 1;
foreach $file (@file) {
my $col = 0;
open(my $FILEHANDLE, "<", $file) or die "cannot open file $file: $!";
my @eachline = <$FILEHANDLE>;
my @keywords = qw{lr_start_transaction web_reg_find lr_think_time web_
+reg_save_param lr_start_sub_transaction web_url web_submit_data};
my $pattern = join("|" => map { "(?<$_>\\b$_\\b)" } @keywords);
my %count;
for (@eachline) {
while (/$pattern/g) {
++$count{(keys %+)[0]};
}
}
$worksheet1-> write($row,$col,(split '/',$file)[-1],$format2);
$col++;
for (@keywords) {
$worksheet1->write($row,$col, "$count{$_}", $format2);
$col++;
}
close($FILEHANDLE);
$row++;
}
Seems %count is not initialized and hence when no pattern is found my writing to XLS is impacted (columns are getting clubbed). I am using Spreadsheet::WriteExcel module.
Let me know if this understanding is correct. Below is the message from the console:
Use of uninitialized value within %count in string at Aldol.pl line 76
+, <$FILEHANDLE> line 550.
Thanks Xhings!