EXPR->{EXPR} is a shorthand for ${EXPR}{EXPR}. Normally, the first EXPR would be a scalar holding a reference, but Perl also support symbolic references. Symbolic references allow variable names to be strings.
>perl -le"$x = "var"; ${$x} = "abc"; print $var;" abc
Furthermore, barewords are treated as strings literals by default (unless they refer to a known function or a file handle is expected where the bareword is located).
>perl -le"$x = main; print $x" main
Using symbolic references is strongly dissuaded. use strict 'refs'; (and therefore just use strict;) prevent them from being used.
Using barewords as string literals is also strongly disuaded. use strict 'subs'; (and therefore just use strict;) prevent them from being used.
So in short, had you used use strict; as you should have, trying to run your snippet would have failed for two different reasons.
In reply to Re: what does main->{x} = 1 do?
by ikegami
in thread what does main->{x} = 1 do?
by ganeshk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |