#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Text::CSV;
use Tie::IxHash;
tie my %general_information, qw(Tie::IxHash);
tie my %ability_scores, qw(Tie::IxHash);
open(my $io, "player_characters.csv") || die("can't open player_characters.csv: $!");
my $csv = Text::CSV_XS->new({
sep_char => '|',
allow_whitespace => 1,
blank_is_undef => 1,
});
$csv->column_names ($csv->getline ($io));
sub list_loop {
my $hash_ref = shift;
print "
\n";
for my $key (keys(%$hash_ref)) {
my $value = $hash_ref->{$key};
print "\t- ".ucfirst $key.": ".$value."
\n";
}
print "
\n";
}
while (defined (my $hr = $csv->getline_hr($io))) {
%general_information = (
"class(es)" => $hr->{class_name},
map { $_ => $hr->{$_} } qw(alignment race gender)
);
%ability_scores = (
map { $_ => $hr->{$_} } qw(strength dexterity constitution intelligence wisdom charisma)
);
print qq{\n};
list_loop(\%general_information);
list_loop(\%ability_scores);
}