Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Using references as hash keys

by Moron (Curate)
on Oct 18, 2005 at 13:56 UTC ( [id://500988]=note: print w/replies, xml ) Need Help??


in reply to Using references as hash keys

re "allows one to use references as hash keys", I didn't realise this was a problem so to be certain I tried this:
#!/usr/bin/perl use Data::Dumper; my $var = "VARVALUE"; my @arr = ( 'ARRVAL1', 'ARRVAL2' ); my %hash = ( hashkey1 => hashval1, hashkey2 => hashval2 ); open my $fh, "| more"; my %HOfR = ( \$var => "valForRefOfVar", \@arr => "valForRefOfArr", \%hash => "valForRefOfHash", \&Sub => "valForRefOfSub", $fh => "valForRefOfGlob" ); print Dumper( \%HOfR ); sub Sub { };
...it produced the expected kind of results, i.e.:
$VAR1 = { 'ARRAY(0x2ddf0)' => 'valForRefOfArr', 'SCALAR(0x2ddd8)' => 'valForRefOfVar', 'GLOB(0x228b4)' => 'valForRefOfGlob', 'HASH(0x2ddcc)' => 'valForRefOfHash', 'CODE(0x456cc)' => 'valForRefOfSub' };
which makes me wonder what the original problem actually is.

-M

Free your mind

Replies are listed 'Best First'.
Re^2: Using references as hash keys
by Roy Johnson (Monsignor) on Oct 18, 2005 at 14:22 UTC
    Those references were converted to strings, which means that you can't get your reference back by looking at keys. But the more important issue (to the OP) was that identical anonymous arrayrefs will not map to the same hash element. That is, each time you mention $HOR{[1,2,3]}, you're talking about a different element.

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-23 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found