4 ms·
``` $addresses = [ { 'name' => 'John Doe', 'address' => '123 Any Street', 'city' => 'Anytown', 'state' => 'TX', }, { 'name' => 'Mary Smith', 'address' => '100 O
by xiaodai 5y ago
```
$addresses = [ { 'name' => 'John Doe', 'address' => '123 Any Street', 'city' => 'Anytown', 'state' => 'TX', }, { 'name' => 'Mary Smith', 'address' => '100 Other Avenue', 'city' => 'Whateverville', 'state' => 'PA', }, ];
```
this already confused me. is the $ vigil for scalars? Why is address using it? Isn't address an array here?
Don't get it.
- 2OEH8eoCRo0 5y agoaddresses is an array reference with two anonymous hash reference elements.
- sloucher 5y agoSo if it's an array, why isn't it @addresses?
- eythian 5y agoIt's an array reference. If you replaced the [ ... ] with ( ... ) you'd have an array and use @. This is something I see people new to Perl struggle with, and I remember it taking me some time to grasp back in the day. It's pretty natural to me now, but I do feel it's something of a wart in the language.
- cutler 5y agoReferences are scalars in Perl. @$ dereferences an array ref and %$ derefs a hash ref. You can also reference a scalar in Perl and deref it with $$ but I never understood why you would want to.