I want to add values from the hash that I created.
my $value_count; foreach my $key (@keys) { $value_count = sum($words{key}, $value_count); }
However, when I run this, I get
Undefined subroutine &main::sum called at C:/Users/Clayton/workspace/main/Main.pl line 54, <$filehandle1> line 174.
I'm not quite sure where I am going wrong. I am new to Perl.
EDIT: I tried using the "+" operator, but I got an error
Use of uninitialized value in addition (+) at C:/Users/Clayton/workspace/main/Main.pl line 54, <$filehandle1> line 174.
Pretty much my hash is similar to Key value cat 2 dog 4 rat 1
So, I am trying to compose all the values, so I can take the average.
EDIT 2: The actual fix is contained in the comments I need to make my $ value_count = 0. This fixed everything. Thank you all. I think this is an important issue that needs to be addressed, and I think it might be useful for someone else, so I'm going to leave it.
source share