I am very new to perl and I am learning this is not like c++. So The user will enter a number of any length, and I want to add each digit and print the sum.
#!/usr/bin/perl -w
use strict;
use warnings;
print "Enter a number :";
my $num = <STDIN>;
my @array = $num;
my $sum=0;
for my $arr (@array){
$sum += $arr;
print $sum;
}
For example the user enters 1234, the sum: 10 the actual result I get is 1234.