#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Text::CSV_XS qw(csv);
sub make_list {
my (%opt) = @_;
my $headers = $opt{'headings'};
my $filters;
for my $header (@$headers) {
if ($header =~ s/\+$//) {
$filters->{$header} = sub { $_ = [split(/;\s*/, $_)]; $_ };
}
}
my $list = csv (
in => $opt{file},
headers => $headers,
key => $opt{key} ? $headers->[0] : undef,
filter => $filters,
sep_char => '|',
quote_char => undef,
empty_is_undef => 1,
allow_whitespace => 1,
) || die Text::CSV_XS->error_diag;
return $list;
}
my $file = 'Artifacts.txt';
my $headers = ['item', 'seen in+'];
print Dumper make_list( file => $file, headings => $headers);
####
Crystal Skull|Stargate SG-1, Crystal Skull; The Librarian: Return to King Soloman's Mines; Indiana Jones and the Kingdom of the Crystal Skull
Spear of Destiny|The Librarian: Quest for the Spear; Hellboy; Constantine
Book or Key of Soloman|The Librarian: Return to King Soloman's Mines; Season of the Witch
Necronomicon|H.P. Lovecraft
Ark of the Covenant|Raides of the Lost Ark; The Librarian: Quest for the Spear
TARDIS|Doctor Who; The Sarah Jane Adventures; The Librarians, And the Final Curtain
Doc Brown's Delorean|Back to the Future; Back to the Future Part II; Back to the Future Part III; The Librarians, And the Final Curtain
Pandora's Box|Warehouse 13; The Librarian: Quest for the Spear
Excalibur|Excalibur; The Last Legion; The Librarian: Quest for the Spear
H.G. Wells' Time Machine|The Librarians; Warehouse 13
Holy Grail|Indiana Jones and the Last Crusade; The Librarian: Quest for the Spear
####
$VAR1 = {
'Ark of the Covenant' => [
'Raides of the Lost Ark',
'The Librarian: Quest for the Spear'
],
'Necronomicon' => [
'H.P. Lovecraft'
],
'Holy Grail' => [
'Indiana Jones and the Last Crusade',
'The Librarian: Quest for the Spear'
],
'H.G. Wells\' Time Machine' => [
'The Librarians',
'Warehouse 13'
],
'Spear of Destiny' => [
'The Librarian: Quest for the Spear',
'Hellboy',
'Constantine'
],
'Book or Key of Soloman' => [
'The Librarian: Return to King Soloman\'s Mines',
'Season of the Witch'
],
'Crystal Skull' => [
'Stargate SG-1, Crystal Skull',
'The Librarian: Return to King Soloman\'s Mines',
'Indiana Jones and the Kingdom of the Crystal Skull'
],
'Doc Brown\'s Delorean' => [
'Back to the Future',
'Back to the Future Part II',
'Back to the Future Part III',
'The Librarians, And the Final Curtain'
],
'TARDIS' => [
'Doctor Who',
'The Sarah Jane Adventures',
'The Librarians, And the Final Curtain'
],
'Pandora\'s Box' => [
'Warehouse 13',
'The Librarian: Quest for the Spear'
],
'Excalibur' => [
'Excalibur',
'The Last Legion',
'The Librarian: Quest for the Spear'
]
};