Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: using hash key as hash value ...

by japhy (Canon)
on Oct 02, 2001 at 04:36 UTC ( [id://116031]=note: print w/replies, xml ) Need Help??


in reply to using hash key as hash value ...

At the time you access the value $media{bond}, it does not yet exist. To get around this, you can do something like:
$_ = "a:default:value" for @hash{'key1', 'key2', 'key3'}; # or $hash{$_} = "a:default:value" for 'key1', 'key2', 'key3'; # or @hash{'key1', 'key2', 'key3'} = ("a:default:value") x 3;
If you actually want one key of a hash to be an alias to another key, you'll have to do some tie() magic.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: using hash key as hash value ...
by blueflashlight (Pilgrim) on Oct 02, 2001 at 07:10 UTC
    yow. that's more involved then I wanted to get into. (Actually, the reason I'm trying to do what I'm trying to do is to make my code "easy" to read for other people at my org. who may need to modify it.)

    Tie::AliasHash looks cool, though ... perhaps I'll try it out sometime.

    thanks! --sandy

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://116031]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-24 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found