in reply to Trying to get sum of elements in array

Your @array has a single element in it, not 5. Change:
my @array = join(' ' , keys %num) . "\n";
to:
my @array = keys %num;

Tip #4 from the Basic debugging checklist: Data::Dumper

use Data::Dumper; print Dumper(\@array);

See also List::Util::sum

Replies are listed 'Best First'.
Re^2: Trying to get sum of elements in array
by Hayest (Acolyte) on Feb 05, 2015 at 18:51 UTC
    Thank you! That works perfectly. I need to look into use Data::Dumper, also.
Re^2: Trying to get sum of elements in array
by wee (Scribe) on Feb 05, 2015 at 18:45 UTC
    I wonder what other homework he has for us...
      Yes, it is homework. Is it an issue that I'm asking for help?
        We're happy to help with homework. It's considered good form to announce it as such, so we can tailor our assistance appropriately (http://www.perlmonks.org/?node_id=172086#homework).

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        Yes, it is homework. Is it an issue that I'm asking for help?
        Frankly not in my view. Sure, it might have been better for you to state upfront that this was homework (this was almost obvious), but you did otherwise everything according to the rules. Especially, you did not ask for someone to write code on your behalf, but just asked for assistance on a specific difficulty with a script that you provided, that compiled correctly and was almost right, but just did not yield the expected result. To me, this is perfectly acceptable, more than that, this is even one of the raisons d'être of this forum, to help people having difficulties with Perl, whether in academic or real life context. So, no problem (IMHO), take it easy.

        If a more senior or experienced monk thinks I am wrong, please let me know.

        Je suis Charlie.