Hi,
I'm starting to look into references, but not everything is clear yet.
This is what I am trying to acheive: I have a list of scalars and I want to build multi-level hash from it (like tree structure).
[tt]
EG:
Given : @array = ("one","two","three"
Result : $hash{one}{two}{three}
[/tt]
This is the small code I wrote, but something is still wrong, probably in the resetting of the reference pointer.
[tt]
# Initialise variables
my @array = ("one","two","three"
my %hash = ();
my $hashref = \%hash;
# Loop for every element in @array
foreach (@array) {
# Add the $_ to hash
$$hashref{$_} = ();
# Redefine the reference pointer
$hashref = \%{$hash{$_}};
}
[/tt]
Can anybody help?
Thanks,
Thierry