P
peter pilsl
I need to rename a hashkey and wonder how to do it best.
The following seems to work:
$hash->{newname}=$hash->{oldname};
delete $hash->{oldname};
But I wonder if this could have longterm-consequences like memleaking or
something cause its a bit complicated, especially if the value itself is a
more complicated construct and I'm paranoid of failing garbage-collection
due to circular references or whatever.
---------------------------
#! /usr/bin/perl -w
use strict;
my $h={
'one'=>{0=>'ten',1=>'eleven',2=>'twelfe?'},
'two'=>{0=>'twenty',1=>'twentyone',2=>'twentytwo'},
'tree'=>{0=>'thirty',1=>'thirtyone',2=>'thirtytwo'}
};
print $h->{tree}->{1},"\n";
$h->{three}=$h->{tree};
delete $h->{tree};
print exists $h->{tree}->{1}?'yes':'no',"\n";
print $h->{three}->{1},"\n";
The following seems to work:
$hash->{newname}=$hash->{oldname};
delete $hash->{oldname};
But I wonder if this could have longterm-consequences like memleaking or
something cause its a bit complicated, especially if the value itself is a
more complicated construct and I'm paranoid of failing garbage-collection
due to circular references or whatever.
---------------------------
#! /usr/bin/perl -w
use strict;
my $h={
'one'=>{0=>'ten',1=>'eleven',2=>'twelfe?'},
'two'=>{0=>'twenty',1=>'twentyone',2=>'twentytwo'},
'tree'=>{0=>'thirty',1=>'thirtyone',2=>'thirtytwo'}
};
print $h->{tree}->{1},"\n";
$h->{three}=$h->{tree};
delete $h->{tree};
print exists $h->{tree}->{1}?'yes':'no',"\n";
print $h->{three}->{1},"\n";