I have the following script:
use 5.12.4;
use strict;
use warnings;
say "Enter a functionality:";
while (<>) {
if (/add/) {
say "Enter your numbers:";
my @a = (<>);
my $sum += $_ for @a;
say $sum;
}
}
When I run this program, it prompts:
Enter a functionality:
I enter add and it says:
Enter your numbers:
I enter several numbers on separate lines of input follow by the [ctrl]Z and get the following error:
Use of uninitialized value $sum in say at C:\myperl\Math-Master\math-master.pl l
ine 11, <> line 9.
Why doesn't my code add all of the input? Why does this error come?
$_ for @ain the failing case?)sumto zero outside the loop fix it?