This seems to do what you want (although your specifications are a bit vague, at least, so I followed your description as close to the letter as I could). Note that I wrote this up while tired (worked over 9 hours during a hectic night at the restaurant) and inebriated (had a couple of drinks afterwards) so it can't be that hard :) Then again, I admit this may not be the most elegant way of going about it, but it does what you want and it should get you on the right track. Even if it's an XY problem.

use strict; use warnings; my $file1 = << "EOF"; # I'm too lazy to create the actual files... >A Amber, Amy >B Barbie, Bambie EOF my $file2 = << "EOF"; # So I'll just define them as heredocs hre... >A Austin, Aurora >C Cathy, Candy EOF my $file3 = << "EOF"; # and read from them in the next part of the c +ode. >B Bob, Barbara >C Cane, Carter EOF my @files = (\$file1, \$file2, \$file3); # References to the scalar +s above. my %names = (); # Oh, you know... a hash. for my $f (@files) { # Iterate through the refe +rences open my $fh, "<", $f; # "Open" them for reading. my $key = ""; # We don't have a key yet. my %tmp_names = (); # Just a temporary hash... $tmp_names{$_} = ["-","-"] for qw(A B C); # ... for the blanks. while (<$fh>) { # Read lines. chomp; # I don't care about newli +nes. if (m/^>([ABC])$/) { # Is it ">" + A, B, or C? $key = $1; # Then it's a key for the +hash. next; } elsif ($key # Do we have a key yet? && $_) { # And it isn't a blank lin +e? my @names = split(/, /, $_); # Then it's a list of name +s! $tmp_names{$key} = \@names; # Store them in the tempor +ary hash } } close $fh; for (qw(A B C)) { push @{$names{$_}}, @{$tmp_names{$_}}; # Move tmp hash to real + hash. } } for (qw(A B C)) { print ">$_\n\n"; print join(", ", @{$names{$_}}), "\n\n"; }

In reply to Re: hash of hashes? by muba
in thread hash of hashes? by sanahmed

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.