in reply to Missing $ on loop variable?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Missing $ on loop variable?
by Anonymous Monk on Nov 06, 2003 at 02:01 UTC | |
by Cody Pendant (Prior) on Nov 06, 2003 at 03:23 UTC | |
by Anonymous Monk on Nov 07, 2003 at 10:45 UTC | |
by Cody Pendant (Prior) on Nov 07, 2003 at 21:11 UTC |