Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: hash key

by mscharrer (Hermit)
on Jul 07, 2009 at 14:52 UTC ( [id://777894]=note: print w/replies, xml ) Need Help??


in reply to hash key

You could use the array address/reference (in string form) as key. It can be questioned if this is really useful, because another array with identical content results in an different reference and therefore different key:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @a = (1,2,3); my %h; $h{\@a} = "value"; my @b = @a; $h{\@b} = "other value"; print Dumper \%h; __END__ $VAR1 = { 'ARRAY(0x84df0e0)' => 'other value', 'ARRAY(0x847c540)' => 'value' };
Like other posts pointed out: You could create a string from the array (like join "\0", @array) and use this as key or maybe use a Tie package. But this all depends on what you really want to do.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found