in reply to Idiomize This - Hash to Array of Hashes

my $speedlist = $heap->{config}{freq_gui}{speedlist}; # (updated, see +AnomalousMonk below) push @cmd_choices, map { {name=>$_, value=>$speedlist->{$_}} } keys %$ +speedlist;

my ($k,$v); push @c, {n=>$k, v=>$v} while ($k,$v) = each %$speedlist;

-Paul

Replies are listed 'Best First'.
Re^2: Idiomize This - Hash to Array of Hashes
by roubi (Hermit) on Apr 20, 2009 at 01:14 UTC
    The push isn't necessary here no?
    my $speedlist = ....; my @cmd_choices = map {{-name=>$_, -value=>$speedlist->{$_}}} keys %$s +peedlist;
      Thanks to both of you:
      my $speedlist = $heap->{config}{freq_gui}{speedlist}; my @cmd_choices = map {{-name=>$_, -value=>$speedlist->{$_}}} keys + %$speedlist;
      It wasn't clear to me if the @cmd_choices already had data in it. If it did, the push was necessary, otherwise, no.

      -Paul

Re^2: Idiomize This - Hash to Array of Hashes
by AnomalousMonk (Archbishop) on Apr 20, 2009 at 01:24 UTC
    my $speedlist = ....;
    The OPer may not be aware that you are now creating and dealing directly with a hash reference, and that the full statement would be
    my $speedlist = $heap->{config}{freq_gui}{speedlist};
    Update: The OPer may not be aware ...     I take that back. Evidently, he is.
      I wasn't aware of it until it wouldn't compile!

      Thanks,

      John