R
rocknmetal20
Hi all,
Is there a way to refer other elements of the hash inside that hash
WHILE I am defining the hash.
Example: I have a hashref with 'x' mapping to an array ref. To save
memory or for someother reason I want to use that same value for 'y'
too.
For the following,
my $a = {
'x' => ['a'],
'y' => ['a'],
};
Instead duplicating the value for y, I want to refer to value for key
'x'.
I can do
my $a = {
'x' => ['a'],
};
$a->{'y'} = $a->{x};
But I want to know, if it can be done while defining the hash.
This does not seem to work:
my $a = {
'x' => ['a'],
'y' => $VAR1->{x}
};
print Dumper($a);
$VAR1 = {
'x' => [
'a'
],
'y' => undef
};
Thanks
Rock
Is there a way to refer other elements of the hash inside that hash
WHILE I am defining the hash.
Example: I have a hashref with 'x' mapping to an array ref. To save
memory or for someother reason I want to use that same value for 'y'
too.
For the following,
my $a = {
'x' => ['a'],
'y' => ['a'],
};
Instead duplicating the value for y, I want to refer to value for key
'x'.
I can do
my $a = {
'x' => ['a'],
};
$a->{'y'} = $a->{x};
But I want to know, if it can be done while defining the hash.
This does not seem to work:
my $a = {
'x' => ['a'],
'y' => $VAR1->{x}
};
print Dumper($a);
$VAR1 = {
'x' => [
'a'
],
'y' => undef
};
Thanks
Rock