The question has already been answered, but I'd like to point out that even if it were possible,
\%hash{'key'} wouldn't be working. You want a single element, a scalar, so it'd be
\$hash{'key'} instead.
Let's cheat!
If you want the references in the hash assignment for readability, and don't use anonymous subs in it, you could abuse those:
%hash = (
foo => 'bar',
bar => sub { 'foo' }
);
(ref() eq 'CODE') && $_ = \$hash{ $_->() } for values %hash;
Same goes for any type of reference. So if you don't use anonymous arrays, you could use:
%hash = (
foo => 'bar',
bar => [ 'foo' ]
);
(ref() eq 'ARRAY') && $_ = \$hash{ $_->[0] } for values %hash;
You could of course cheat using some common prefix of which you're sure not to use it for any other purpose:
%hash = (
foo => 'bar',
bar => 'REF:foo'
);
/^REF:(.+)/ and $_ = \$hash{$1} for values %hash;
Or just replace the hash assignment with a lot of key assignments:
%hash = ();
for (
[ foo => 'bar' ],
[ bar => \$hash{foo} ]
) {
$hash{ $_->[0] } = $_->[1];
}
Or use a temporary hash:
%hash = ();
%temp = (
foo => 'bar',
bar => \$hash{foo}
);
$hash{$_} = $temp{$_} for keys %temp;
BTW: I'm not really being serious.
++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
-- vs lbh hfrq OFQ pnrfne ;)
- Whreq
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.