perl -e'%hash=(1,"a",2,"b",3,"c"); foreach keys ( %hash ) { print }' Missing $ on loop variable at -e line 1. perl -e'%hash=(1,"a",2,"b",3,"c"); foreach ( %hash ) { print }' 1a3c2b perl -e'%hash=(1,"a",2,"b",3,"c"); foreach $keys ( %hash ) { print $ke +ys }' 1a3c2b perl -e'%hash=(1,"a",2,"b",3,"c"); foreach ( keys %hash) { print }' 132
Nothing wrong with ( %hash ), but keys looks like a loop variable in that context (as hardburn describes well).
Warnings and error messages are usually complaining about the right thing (at least in some way). If you think its wrong, read it again. I speak from personal experience of being too ready to disbelieve error codes. More often than not the simplest reading is the right one.
In reply to Re: Missing $ on loop variable?
by qq
in thread Missing $ on loop variable?
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |