Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Better way of doing!

by Xhings (Acolyte)
on Aug 21, 2013 at 09:26 UTC ( [id://1050314]=note: print w/replies, xml ) Need Help??


in reply to Re: Better way of doing!
in thread Better way of doing!

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!

Replies are listed 'Best First'.
Re^3: Better way of doing!
by kcott (Archbishop) on Aug 21, 2013 at 10:26 UTC

    If you want to initialise all counts to zero, do this:

    my %count = map { $_ => 0 } @keywords;

    Also, see my update: that's probably a better choice of code for your application.

    -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1050314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found