Basically my data is subject to change but will follow a format as follows where I will have a unique "Family Name" followed by "--" followed by various "family members". The contents of the data are unknown to me apart from the format: Data is a text file as follows:
I know I can grab this into an array called @Dopli. And split each line $unix at "--" into an array @trainer Is there a way of pushing each array into a hash using $trainer[0] and $trainer1.
Ultimately I am looking to print:
However, all I am getting is the number of terms within each array of the hash.
Thanks for any kind of help or advice
Code:
FLINTSTONES=BARNEY, FRED, WILMA
JETSONS=MAX, TONY, WILMA
SIMPSONS=LISA, BARNEY, WILMA, HOMER
ALCATRAZ=ELIJAH, MAX, WILMA
I know I can grab this into an array called @Dopli. And split each line $unix at "--" into an array @trainer Is there a way of pushing each array into a hash using $trainer[0] and $trainer1.
Code:
sub nice_list {
return '' if @_ == 0;
return shift if @_ == 1;
my $last = pop;
return join(', ', @_) . " and $last";
}
my $unix;
my @dopli;
my @trainer;
foreach $unix (@dopli){
@trainer = split ('=', $unix);
@truth = split (',', $trainer[1]);
my %is_eaten_by = (
$trainer[0] => [ (@truth) ],
);
foreach my $fruit (keys %is_eaten_by) {
my $eaters = $is_eaten_by{$fruit};
my $num_eaters = @$eaters;
print("$num_eaters ${fruit}: ",
(@$eaters), "\n");
}
}
Ultimately I am looking to print:
Code:
BARNEY can be found 2: FLINTSTONES SIMPSONS
FRED can be found 1: FLINTSTONES
WILMA can be found 4: FLINTSTONES JETSONS SIMPSONS ALCATRAZ
MAX can be found 2: JETSONS ALCATRAZ
and so forth...
However, all I am getting is the number of terms within each array of the hash.
Thanks for any kind of help or advice