http://qs1969.pair.com?node_id=500988


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.