When you use the -> operator the '$' sigil is not necessary!
It has nothing to do with the -> operator. Few if any operators requires its operands to have a $ since they work on expressions, not specifically scalars.
For example, here are 4 different operators and not a sigil in sight:
foo()->{x} foo() + bar() !foo() print(foo())
Perl automatically understands the type i.e whether array or hash.
Correct.
EXPR->[...] expects EXPR to return an array reference.
EXPR->{...} expects EXPR to return a hash reference.
EXPR->(...) expects EXPR to return a code reference.
And also the variable is defined in the current package. Is that correct?
No. Symbolic references can access variables in any package.
>perl -le"$x='Foo::var'; ${$x}='abc'; print $Foo::var;" abc
And it happens because strict refs is off.
strict shouldbe used. It's there to prevent specifically these kinds of odd and hard to debug problems.
In reply to Re^3: what does main->{x} = 1 do?
by ikegami
in thread what does main->{x} = 1 do?
by ganeshk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |