in reply to Getting element of anonymous hashref
Perl interprets
{("foo","bar")}
as a code block containing two constants, as you can see by the warnigns Perl gives:
perl -we "{('foo','bar')}" Useless use of a constant in void context at -e line 1. Useless use of a constant in void context at -e line 1.
You need to tell Perl that you mean a hash constructor instead of a code block by prepending (for example) a + to the expression:
perl -we "+{(foo => 'bar')}" Useless use of single ref constructor in void context at -e line 1.
If you put that together, it works:
perl -we "print +{(foo => 'bar')}->{foo}" bar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting element of anonymous hashref
by pseudomonas (Monk) on Oct 16, 2006 at 12:51 UTC |