Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

isn't numeric in substr error

by begood321 (Novice)
on Nov 17, 2010 at 02:12 UTC ( #871896=perlquestion: print w/ replies, xml ) Need Help??
begood321 has asked for the wisdom of the Perl Monks concerning the following question:

Instead of parsing spreadsheet for value I have decided to check variable value instead. I can't seem to get my value to pass from subroutine to subroutine call as seen below. I get values in logger reports1 but not in logger reports2.
@reports = &getValidTotals(); $logger->write_log("reports2: @reports", "INFO");. . . . . sub getValidTotals ($$) { my $reportGroup = $_[0]; my $total = $_[1]; my @reports = qw(); if ($reportGroup ne "") { push(@reports,$reportGroup); $logger->write_log("reports1: @reports, total: $total", "INFO"); } return @reports; }

Comment on isn't numeric in substr error
Download Code
Re: isn't numeric in substr error
by kcott (Abbot) on Nov 17, 2010 at 02:36 UTC

    You're calling outputHeader() like this:

    &outputHeader(*REPORT_HANDLE,$worksheet{$criterion},$reportPath,$crite +rion,"all"); &outputHeader(*REPORT_HANDLE,$worksheet{$group},$reportPath,$criterion +,$group);

    Then, in sub outputHeader, you're reading the arguments like this:

    sub outputHeader { my $reportHandle = $_[0]; my $reportPath = $_[1]; my $group = $_[2]; my $criterion = $_[3]; my $worksheet = shift; ...

    Either call with $reportPath as 2nd argument or alter the sub to read it as the 3rd argument.

    I suspect other issues with naming conventions: $worksheet{$group}, $worksheet, $group

    -- Ken

      sub outputHeader { my $reportHandle = $_[0]; my $reportPath = $_[1]; my $group = $_[2]; my $criterion = $_[3]; my $worksheet = shift;
      Also, it's usually not a good idea to mix my $var = $_[0] and my $var = shift-style handling of arguments (unless you know what you're doing and why...:)

      In this case, $worksheet will have the same value as $reportHandle. Not sure if this is intended. If so, it's clearer to directly write my $worksheet = $reporthandle;

        Thanks Ken and Anonymous your suggestions helped which I have implemented. I'm getting undef where I defined sub/variables. Errors location are numbered in code (line no.)

        Updated code.

        our %worksheet; #header foreach my $criterion (@criteria) { $reportPath = "$report_loc/$criterion.xls"; $reportHash{$criterion}{"all"}{"reportPath"} = $reportPath; local *REPORT_HANDLE; if (! open(REPORT_HANDLE, ">$reportPath")) { abort("Couldn't open $reportPath: $!"); } binmode REPORT_HANDLE; # Always do this regardless of whether the +platform requires it. $reportPath = Spreadsheet::WriteExcel->new(\*REPORT_HANDLE); $worksheet{$criterion} = $reportPath->add_worksheet($criterion); &outputHeader(*REPORT_HANDLE,$reportPath,"all",$criterion,$workshe +et{$criterion}); $reportHash{$criterion}{"all"}{"reportHandle"} = *REPORT_HANDLE; $reportHash{$criterion}{"all"}{"total"} = 0; foreach my $group (@groups) { $reportPath = "$report_loc_ts_groups/$group/$group" . "_" . "$crit +erion.xls"; $reportHash{$criterion}{$group}{"reportPath"} = $reportPath; local *REPORT_HANDLE; if (! open(REPORT_HANDLE, ">$reportPath")) { abort("Couldn't open $reportPath: $!"); } binmode REPORT_HANDLE; # Always do this regardless of whether the +platform requires it. my $reportPath = Spreadsheet::WriteExcel->new(\*REPORT_HANDLE +); $worksheet{$group} = $reportPath->add_worksheet($group); &outputHeader(*REPORT_HANDLE,$reportPath,$group,$criterion,$wo +rksheet{$group}); $reportHash{$group}{$criterion}{$worksheet{$criterion}}{"repor +tHandle"} = *REPORT_HANDLE; $reportHash{$group}{$criterion}{$worksheet{$criterion}}{"total +"} = 0; } } # Print totals and close files! foreach my $criterion (@criteria) { (line 229) wrapUp($reportHash{"all"}{$criterion}{$worksheet{$criterio +n}}{"reportHandle"},$reportHash{"all"}{$criterion}{$worksheet{$criter +ion}}{"total"}); foreach my $group (@groups) { wrapUp($reportHash{$group}{$criterion}{$worksheet{$group}}{"report +Handle"},$reportHash{$group}{$criterion}{$worksheet{$group}}{"total"} +); } # End of foreach my $group (@groups) { } # End of foreach my $criterion (@criteria) { exit; sub outputHeader { my $reportHandle = $_[0]; my $reportPath = $_[1]; my $group = $_[2]; my $criterion = $_[3]; my $worksheet = $_[4]; my ($x,$y)=(0,0); my $groupOut = ""; if ($groupOut ne "all") { $groupOut = "$group - "; } my $criterionOut = "Files expire within current month ($current_y-$cu +rrent_mth)"; if ($criterion eq $criteria[1]) { $criterionOut = "Deleted (expired) Files"; } elsif ($criterion eq $criteria[2]) { $criterionOut = "Files found with invalid expiry_date"; } #$worksheet->write($y++, $x, "$groupOut$criterionOut" +, $format{bold}); # write_string() $worksheet->write($y++, $x, "$groupOut$criterionOut" + ); # write_string() $worksheet->write($y++, $x, "Date Run: ".localtime()."" + ); # write_string() $worksheet->write($y++, $x, + ); # write_blank() $worksheet->write($y++, $x, "Criteria: today's date : $tod_date" + ); # write_string() $worksheet->write($y++, $x, " time interval : on or before +today's date" ); # write_string() if ($group ne "all") { $worksheet->write($y++, $x, " teamsite group : $group" + ); # write_string() } $worksheet->write($y++, $x, " workarea : \$area" + ); # write_string() $worksheet->write($y++, $x, " directories : " + ); # write_string() $worksheet->write($y++, $x, + ); # write_blank() $worksheet->write($y++, $x, + ); # write_blank() $worksheet->write($y++, $x, uc($groupOut.$criterionOut) + ); # write_string() $worksheet->write($y++, $x, + ); # write_blank() # Simple text $worksheet->write($y++, $x, "Files"); } # End of sub outputHeader { sub wrapUp { my $reportHandle = $_[0]; my $reportPath = $_[1]; my $group = $_[2]; my $criterion = $_[3]; my $worksheet = $_[4]; my $total = $_[5]; my ($x,$y) = (0,16); (line 314) $worksheet->write($y++, $x, "total"); close($reportHandle); } # End of sub wrapUp {

        Log error I'm getting

        Uncaught exception from user code:

        Can't call method "write" on an undefined value at /home/bsmart/excel_workbooks.ipl line 314.

        main::wrapUp('undef','undef') called at /home/bsmart/excel_workbooks.ipl line 229

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://871896]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-07-26 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (179 votes), past polls