in reply to Dynamically named hashes (w or w/o strict)

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.

Replies are listed 'Best First'.
Re^2: Dynamically named hashes (w or w/o strict)
by chrishowe (Acolyte) on Dec 11, 2008 at 15:39 UTC
    I think that has done the job *and* explained it.
    Cheers :-)