new to perl, trying to playing around with its syntax a bit, then I got this error message
$ perl testP
syntax error at testP line 3, near "$_ ("
Execution of testP aborted due to compilation errors.
for:
$_=$_+1 foreach $_ (@_);
Can anyone tell me what went wrong and how to fix it? thanks.
foreach variable ( array ) is used in normal notation like:
But you used the reverse notation, that is operation first, and loop then.
In this case you cannot provide variable name for the loop (which is useless anyway, since you’re using default variable $_), and the loop should look:
Please also note that you can use
forinstead offoreach, and if you simply want to increment variable, you can do it with ++ operator, thus making it to: