Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Adding and Multplying Elements in an Array

by djantzen (Priest)
on Jun 18, 2003 at 01:43 UTC ( #266699=note: print w/replies, xml ) Need Help??


in reply to Adding and Multplying Elements in an Array

Using an undef variable in a mathematical operation causes its value to begin at zero. I don't see a formal explanation in perlop, but I would speculate that under warnings or -w you see the message regarding $sum2 being uninitialized because zero times anything is zero, and perl probably figures that you want to know in advance that you're performing a computation guaranteed to result in zero. Addition works because adding to zero isn't a problem. The solution therefore is to initialize $sum2 with a non-zero value.


"The dead do not recognize context" -- Kai, Lexx
  • Comment on Re: Adding and Multplying Elements in an Array

Replies are listed 'Best First'.
Re: Re: Adding and Multplying Elements in an Array
by Dru (Hermit) on Jun 18, 2003 at 01:47 UTC
    I set  $sum2 = 1 and that seem to do it. Thanks.
      yes that's the way to tackle..... suresh

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2020-06-02 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (13 votes). Check out past polls.

    Notices?