R
Rocky
hi all,
this subroutine was written originally without the if/else statement for
$total. It returned any non-zero sum perfectly but whenever @number was
all zeros it came back blank(undefined?) What did I miss? It works now
but it soesn't seem to be the best way. Thank you.
Rocky
sub addnums {
my @number = @_;
my $total;
my $digit;
foreach $digit (@number)
{
$total += $digit;
}
if (defined($total))
{
$total = $total;
}
else
{$total = 0;}
return $total;
}
this subroutine was written originally without the if/else statement for
$total. It returned any non-zero sum perfectly but whenever @number was
all zeros it came back blank(undefined?) What did I miss? It works now
but it soesn't seem to be the best way. Thank you.
Rocky
sub addnums {
my @number = @_;
my $total;
my $digit;
foreach $digit (@number)
{
$total += $digit;
}
if (defined($total))
{
$total = $total;
}
else
{$total = 0;}
return $total;
}