Keep It Simple, Stupid | |
PerlMonks |
Re^2: Good Perl book?by Athanasius (Archbishop) |
on Feb 11, 2017 at 02:45 UTC ( [id://1181726]=note: print w/replies, xml ) | Need Help?? |
This is actually pretty close to what you wanted. Un-comment use warnings and the resulting message will help to identify the problem:
The problem loop is:
and as the output shows, the loop value is always one greater than the index. That’s because arrays in Perl (as in C) are subscripted starting from zero, so $arr[1] is actually the second element. The loop is easily fixed:
Also un-comment use strict, and you’ll see that the only error message pertains to this line:
Declare $num as a lexical variable:
and strict is happy. Hope that helps,
In Section
Seekers of Perl Wisdom
|
|