Adding indexes with PERL

Hello. I'm trying to self learn Perl and am stuck. I have a data.csv file that contains the following:

5,10,15,20,15,30
1,2,3,4,5
3,10
11

I'm trying to get Perl to take the indexes and add them all together to get 134. It says I need to use split and invoke the file via
<> (built-in provides data from files and standard-in) the command line. So I'm doing ./test.pl data.csv to run it but I'm just
getting 4 lines containing a single 0. Any pointers?

Here is the code I have so far:

#!/usr/bin/perl

while (<>){
$total=(split/,/,$input);

print$total;
print ("\n");
}


Moderator comments were removed during original forum migration.

Your task is pretty basic. You will find a lot of examples if you...

... search google for "perl read from stdin" ...
... read the documentation for the functions, e. g. perldoc -f split

I do not see where you are assigning a value to your variable $input , which you'd like to split.

1 Like