in reply to Sorting a hash of a hash using anonymous subs

I don't see the need to deref the hashref into a separate hash - it seems much handier as it stands. For example:
for my $mainkey ( sort keys %$hashref ) { # but then use it my $total = $hashref -> { $mainkey ) { Total }; my $value = $hashref -> { $mainkey ) { Value }; # and do whatever with those }

-M

Free your mind

Replies are listed 'Best First'.
Re^2: Sorting a hash of a hash using anonymous subs
by madbombX (Hermit) on Jul 27, 2006 at 18:59 UTC
    The reason that I use a has instead of a hashref is that it is used as a hash through the rest of the program. In order to continue this without having to rewrite everything, I just dereference it into a regular hash when I Storable::retrieve() it.

    Eric

      I'm not pushing that issue then, but you could still do something like this:
      for my $mainkey ( sort keys %copy ) { my $subref = $copy{ $mainkey }; my $total = $subref -> { Total }; my $value = $subref -> { Value }; # process $mainkey, $total and $value ... }

      -M

      Free your mind