XP is just a number | |
PerlMonks |
Re: Finding sum of numbers and storing it an Arrayby hippo (Bishop) |
on Sep 21, 2020 at 09:20 UTC ( [id://11121988]=note: print w/replies, xml ) | Need Help?? |
I have wrote a program that stores five numbers in different variables This is the part which is confusing. You clearly know how to use arrays so why not start with an array?
That way your sum could be written:
or alternatively
And your final array assignment could become
By starting off with separate scalars, everything you do becomes repetitive. It's feasible for 5 numbers, but what about 30? or 100? or 1000000? The other thing I would change is to remove the -w from the first line. Using warnings as you have done is better as it gives lexical scope and finer control where needed. The -w negates all that. 🦛
In Section
Seekers of Perl Wisdom
|
|