in reply to Implicit context conversion error, brain.pl line 666
The problem was coming back to Perl after spending a lot of time writing PHP code, where variables inside functions are locally scoped by default.
And where the only efficient loop over numbers is a C-style loop. Your example can do without variables completely:
Note that I also have put the sub at the top. If you put your sub at the bottom, _ALL_ lexicals that aren't in a block are shared by subs.sub foo { for (1..3) { print; } print "\n"; } for (0..9) { foo; }
sub foo { print for 1..3; print "\n"; } foo for 0..9;
U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk
|
|---|