Now that I have calmed down from a rotten day at work, I think that I can ask a cohesive question. As you will see, this example code consists of 2 subroutines, each returning different information regarding my "dogs". What I want to do, is to put all of the data into one hash so that I can print all the data together. The "code":
#!/usr/local/bin/perl -w use strict; my $dogdir = "/path/to/colors"; my $typedir = "/path/to/type"; my ($color_file, @color_list, $color_blurb, @type_list, $type_string, + $type_value, @breed) my %colors = (); my %type = (); my %dogs = ( barky => 1, fluffy => 1, licky => 1 ) &colors; &type; sub colors { opendir (DOGDIR, $dogdir) or die "Cannot open $dogdir: $!" ; while ( defined ($color_file = readdir (DOGDIR))) { @color_list = `cat $dogdir/$color_file | grep COLOR`; my $color = $_; if (exists $dogs{$color}) { foreach $color_blurb(@colorlist) { push @{$colors{$color_file}}, $color_blurb; } foreach $color_file (sort keys %colors) { $color_blurb = join "", @{$colors{$color_file}}; print "$color__file:\n"; print "===========================\n"; print "$color_blurb\n\n"; } } } } sub type { opendir (TYPEDIR, $typedir) or die "Cannot open $typedir: $!" ; while ( defined ($type_file = readdir (TYPEDIR))) { @type_list = `cat $typedir/$type_file |grep Breed` ; if (exists $dogs{$color}) { foreach $type_string(@type_list) { @breed = split(' ',$type_string); if ($type_string =~ m/(is.*?),/) { $type_value = ("$i[2] $1"); push @{$type{$type_file}}, $type_value; } } } foreach $type_file (sort keys %type) { print "$type_file\n"; print "===========================\n"; print "$type_value\n\n"; } } }
The subroutine "colors" prints:
Barky =========================== is brown Fluffy =========================== is black Licky =========================== is bald
The subroutine type prints:
Barky =========================== is a beagle Fluffy =========================== is a terrier Licky =========================== is a bald mutt
I want the program to print:
Barky =========================== is brown is a beagle etc., etc, etc,

In reply to Hash Question by Limo

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.