in reply to what is the variable type of $data = {
In this piece of code, { starts a new, anonymous hash (that doesn't have a variable name of its own) and returns a reference to it. The reference is stored in the scalar variable named $data. The hash contains three keys a10, bbb, a2 and the values they have (still scalars) are also hash references.
There are two syntactically different ways to access a hash by reference: $data->{$key} (the arrow operator, ->) and ${$data}{$key} (wrap the reference in {} - where you could also put the name of the hash if it had a name). Both ways take $data, try to dereference it, access the underlying hash and return the scalar value referenced by key $key. If $data does not contain a hash reference, an exception will be raised (but if $data is undef, an anonymous hash may be created automatically and a reference to it may be stored inside $data - see autovivification).
See perlreftut and perldsc for more info.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: what is the variable type of $data = {
by jimyokl (Novice) on Jun 20, 2019 at 12:14 UTC |