I have two hash, first one %hash contain uniq key and values.
The other one %channel contain only the Stores which are already present as values from %hash
I would like to display all the Category id (for example Category::1375567 etc..) which refer to the Store (for example Store::CAR)
Here below the expected result of what I need, it will be more efficient than my explication.
my %hash = (
'Category::1375567' => 'Store::CAR|Category::1375567|CAR Concert',
'Category::1299556' => 'Store::CHANNEL|Category::1299556|Culture',
'Category::1314571' => 'Store::TV|Category::1314571|Emissions',
'Category::1375568' => 'Store::CAR|Category::1375568|Sciences',
'Category::1314570' => 'Store::TV|Category::1314570|Info',
'Category::1314572' => 'Store::TV|Category::1314572|Jeunesse',
'Category::1314569' => 'Store::TV|Category::1314569|Séries & Fictions',
'Category::1294556' => 'Store::CHANNEL|Category::1294556|Documentaire',
'Category::1326557' => 'Store::CHANNEL|Category::1326557|Sport'
);
my %channel = (
'Store::TV' => 'Store::TV',
'Store::CAR' => 'Store::CAR',
'Store::CHANNEL' => 'Store::CHANNEL'
);
Expected result
Store::CAR
Store::CAR|Category::1375567|CAR Concert
Store::CAR|Category::1375568|Sciences
Store::CHANNEL
Store::CHANNEL|Category::1294556|Documentaire
Store::CHANNEL|Category::1299556|Culture
Store::CHANNEL|Category::1326557|Sport
Store::TV
Store::TV|Category::1314569|Séries & Fictions
Store::TV|Category::1314570|Info
Store::TV|Category::1314571|Emissions
Store::TV|Category::1314572|Jeunesse
Actual result
Store::CAR
Store::CAR|Category::1375567|CAR Concert
Store::CAR|Category::1375568|Sciences
Store::CHANNEL|Category::1294556|Documentaire
Store::CHANNEL|Category::1299556|Culture
Store::CHANNEL|Category::1326557|Sport
Store::TV|Category::1314569|Séries & Fictions
Store::TV|Category::1314570|Info
Store::TV|Category::1314571|Emissions
Store::TV|Category::1314572|Jeunesse
Store::CHANNEL
Store::CAR|Category::1375567|CAR Concert
Store::CAR|Category::1375568|Sciences
Store::CHANNEL|Category::1294556|Documentaire
Store::CHANNEL|Category::1299556|Culture
Store::CHANNEL|Category::1326557|Sport
Store::TV|Category::1314569|Séries & Fictions
Store::TV|Category::1314570|Info
Store::TV|Category::1314571|Emissions
Store::TV|Category::1314572|Jeunesse
Here what I've done so far
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use feature 'say';
my %hash = (
'Category::1375567' => 'Store::CAR|Category::1375567|CAR Concert',
'Category::1299556' => 'Store::CHANNEL|Category::1299556|Culture',
'Category::1314571' => 'Store::TV|Category::1314571|Emissions',
'Category::1375568' => 'Store::CAR|Category::1375568|Sciences',
'Category::1314570' => 'Store::TV|Category::1314570|Info',
'Category::1314572' => 'Store::TV|Category::1314572|Jeunesse',
'Category::1314569' => 'Store::TV|Category::1314569|Séries & Fictions',
'Category::1294556' => 'Store::CHANNEL|Category::1294556|Documentaire',
'Category::1326557' => 'Store::CHANNEL|Category::1326557|Sport'
);
my %channel = (
'Store::TV' => 'Store::TV',
'Store::CAR' => 'Store::CAR',
'Store::CHANNEL' => 'Store::CHANNEL'
);
if (%channel) {
foreach (sort keys %channel) {
say "\t", $_;
my @tab = grep{/'$_'/} sort values %hash;
if (@tab) {
foreach my $line (@tab) {
say $line;
}
say "";
}
}
}
#say Dumper(\%hash, \%channel);
__END__