Is there a compelling reason not to just use anonymous hashes for your problem? Why do your variable names need to be set a run-time? For most problems the headaches introduced by not using strict outweigh the benefits.
use strict;
my @array = ();
my $hash_ref = {one => "number"};
$hash_ref->{"a"} = "letter";
push @array, $hash_ref;
$hash_ref = {};
%{$hash_ref} = (banana => "fruit",
carrot => "vegetable");
push @array, $hash_ref;
for my $element (@array) {
for (sort keys %{$element}) {
print "$_ => $element->{$_}\n";
}
}
For for info on arrays, hashes, etc. check out perldata and, for the fancy stuff, perldsc. |