in reply to Update: problem with scalar

Hello sargg55,

foreach my $scalar(@array) { $total+=scalar; }

You’ve named the foreach variable $scalar, but in the loop body you’ve left off the $ sigil. Now, it so happens that scalar is a built-in function in Perl (it puts its argument into scalar context), so the interpreter thinks you’re calling the function — without an argument. Add the sigil:

$total += $scalar;

and it should compile cleanly. See scalar.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Update: problem with scalar
by sargg55 (Novice) on Apr 24, 2016 at 03:14 UTC
    Thanks !, fixed that, and now it spawned another problem
    Use of uninitialized value in addition (+) at a18.pl line 27. Use of uninitialized value in addition (+) at a18.pl line 27. Use of uninitialized value in subtraction (-) at a18.pl line 28. Use of uninitialized value in subtraction (-) at a18.pl line 28. Use of uninitialized value in division (/) at a18.pl line 29. Use of uninitialized value in division (/) at a18.pl line 29. Illegal division by zero at a18.pl line 29.
    sigh
      You should print out your @array to make sure it contains what you think it does:
      use Data::Dumper; # ... # build @array # ... print Dumper( \@array );
      Your @array variable is probably not properly populated and is likely to be empty (at least in part). This suggest that you might have an earlier problem reading the testFile.txt file.

      Perhaps you could change the file opening line as follows:

      open FILE, "<", 'testFile.txt' or die "Cannot open testFile.txt $!";
      This will not solve the problem but at least it would tell you if the program failed to open the file.

      BTW, you should always check whether such OS related statements succeed.