#!/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";
}
}
}
####
Barky
===========================
is brown
Fluffy
===========================
is black
Licky
===========================
is bald
####
Barky
===========================
is a beagle
Fluffy
===========================
is a terrier
Licky
===========================
is a bald mutt
####
Barky
===========================
is brown
is a beagle
etc., etc, etc,