If I open a file with strings like “233445”, how can I then split that string into digits “2 3 3 4 4 5” and add each one to each other “2 + 3 + 3 etc…” and print out the result.
My code so far looks like this:
use strict;
#open (FILE, '<', shift);
#my @strings = <FILE>;
@strings = qw(12243434, 345, 676744); ## or a contents of a file
foreach my $numbers (@strings) {
my @done = split(undef, $numbers);
print "@done\n";
}
But I don’t know where to start for the actual add function.
or
PS — Always use
use strict; use warnings;. It would have detected your misuse of commas inqw, and it would have dected your misuse ofundefforsplit‘s first argument.