Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Creating Reports with hashes: Use of uninitialized value while adding integers

by jwkrahn (Monsignor)
on Jan 26, 2012 at 16:15 UTC ( #950155=note: print w/ replies, xml ) Need Help??


in reply to Creating Reports with hashes: Use of uninitialized value while adding integers

You need to change:

for my $size (@sizeOfTrees) { my $quant = $tree_collection{$years}{$trees}{$size} || "-" +; printf "%9s", "$quant"; # { no warnings; $total += $quant; } # WHY DO I NEED TH +IS? }

To:

for my $size (@sizeOfTrees) { my $quant = $tree_collection{$years}{$trees}{$size} || 0; printf "%9s", $quant || '-'; $total += $quant; }


my $quantity = (); my $total_quantity = (); my $total = (); my $year_total = ();

Why are you trying to assign a list to a scalar variable?    Don't do that, it makes no sense!

printf "%9s", "$quant"; printf "%5s", "$total"; printf "%9s", "$total_col{$i}"; printf "%5s", "$year_total";

Don't quote scalar variables.    Perl is not a shell!    What's wrong with always quoting "$vars"?


Comment on Re: Creating Reports with hashes: Use of uninitialized value while adding integers
Select or Download Code
Replies are listed 'Best First'.
Re^2: Creating Reports with hashes: Use of uninitialized value while adding integers
by ikegami (Pope) on Jan 26, 2012 at 18:20 UTC

    Why are you trying to assign a list to a scalar variable? Don't do that, it makes no sense!

    It may not be the most readable, but that doesn't meant it makes no sense.

    Not to mention, no list op or list value is involved. Empty parens in scalar context evaluate to undef.

Re^2: Creating Reports with hashes: Use of uninitialized value while adding integers
by GertMT (Friar) on Jan 26, 2012 at 16:31 UTC
    Great help and some extra tips.

    I meant to assign the scalars to UNDEF. Now changed, as proposed by others, declaring the scalar variables to 0;

    It looks much cleaner with the NOT quoted scalar variables.

    Thanks again.

      I meant to assign the scalars to UNDEF.

      $foo = (); will indeed do that, but since scalars are initialised to undef on creation, my $foo; is sufficient.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (17)
As of 2015-07-30 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls