Issue: You have a almost-regular data structure (HoHoH), with a redundant key in the middle that you want to omit from the derived hash (%reasons).

Solution: Traverse the HoHoH regularly with ( while(each){while(each){while(each){}}} ), just as if the middle key is not static. Omit the middle key when forming the key for %reasons, but check for duplicates as a help to future maintenance programmers. Alternately, you could make reasons an AoA.

!/usr/bin/perl -w use strict; my $switch_hash = { 'Washington' =>{uslecwas5e1 =>{'01-AUG-2002' => '' }}, 'Charleston' =>{uslecchst5e1 =>{'01-AUG-2002' => '' }}, 'Richmond' =>{uslecric5e1 =>{'01-AUG-2002' => '' }}, 'West Palm Beach'=>{uslecwpb5e1 =>{'01-AUG-2002' => '' }}, 'Atlanta' =>{uslecatl5e1 =>{'14-AUG-2002' => '10:reason', '15-AUG-2002' => '11:new reason' +}}, 'Fort Myers' =>{uslecftm5e1 =>{'01-AUG-2002' => '' }}, 'Mobile' =>{uslecmob5e1 =>{'01-AUG-2002' => '' }}, 'Nashville' =>{uslecnas5e1 =>{'01-AUG-2002' => '' }}, 'Orlando' =>{uslecorl5e1 =>{'12-AUG-2002' => '2:different rea +son' }}, 'Charlotte' =>{uslechar5e1 =>{'01-AUG-2002' => '' }}, 'Louisville' =>{usleclou5e1 =>{'01-AUG-2002' => '' }}, 'Memphis' =>{uslecmem5e1 =>{'01-AUG-2002' => '' }}, 'Philadelphia' =>{uslecphi5e1 =>{'01-AUG-2002' => '' }}, 'Chattanooga' =>{uslecchat5e1 =>{'01-AUG-2002' => '' }}, 'Birmingham' =>{uslecbir5e1 =>{'01-AUG-2002' => '23:junk' }}, 'Greensboro' =>{uslcgb5e2sm =>{'01-AUG-2002' => '' }}, 'New Orleans' =>{uslecnew5e1 =>{'01-AUG-2002' => '22:fake' }}, 'Jacksonville' =>{uslecjac5e1 =>{'01-AUG-2002' => '' }}, 'Norfolk' =>{uslecnor5e1 =>{'01-AUG-2002' => '' }}, 'DEX' =>{chrdex =>{'13-AUG-2002' => '1:some stuff', '19-AUG-2002' => '1:reason again' + }}, 'Atlanta II' =>{uslecat25e1 =>{'01-AUG-2002' => '' }}, 'Baltimore' =>{uslecbal5e1 =>{'01-AUG-2002' => '' }}, 'Raleigh' =>{uslecral5e1 =>{'01-AUG-2002' => '' }}, 'Pittsburgh' =>{uslecpit5e1 =>{'01-AUG-2002' => '' }}, 'Miami' =>{uslecmia5e1 =>{'01-AUG-2002' => '' }}, 'Knoxville' =>{uslecknxv5e =>{'01-AUG-2002' => '' }}, 'Tampa' =>{uslectam5e1 =>{'01-AUG-2002' => '' }}, }; my %reasons; while ( my ($city, $v1) = each %$switch_hash ){ while ( my ($usl, $v2) = each %$v1 ){ while ( my ($date, $v3) = each %$v2 ){ next unless $v3; my ($hours, $reason) = split ':', $v3, 2; warn if exists $reasons{"$city:$date"}; $reasons{"$city:$date"} = $reason; # push @reasons, [$city, $date, $reason ]; $v2->{$date} = $hours; # Can't use $v3 here; it is a copy! } } } use Data::Dumper; $Data::Dumper::Useqq = 1; print Data::Dumper->Dump( [ \%reasons, $switch_hash ], [qw( *reasons switch_hash )] );

In reply to Re: newbie question on HoH manipulation by Util
in thread newbie question on HoH manipulation by gnu@perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.