I am trying to combine two scripts into one, but I can't figure out how to get the variable names to work with Text::CSV. Everything I try to combine these two scripts doesn't work. I will spare you the csv file, but if you want to see it, it is here.
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Text::CSV;
use Data::Dumper;
open(my $io, "player_characters.csv") || die("can't open player_charac
+ters.csv: $!");
my $csv = Text::CSV_XS->new({
sep_char => '|',
allow_whitespace => 1,
always_quote => 1,
blank_is_undef => 1,
});
my @names = $csv->getline($io);
$csv->column_names (@names);
while (defined (my $hr = $csv->getline_hr($io))) {
print Dumper($hr);
}
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Tie::IxHash;
tie my %general_information, qw(Tie::IxHash);
tie my %ability_scores, qw(Tie::IxHash);
my ($id_name, $filename, $last_name, $first_name, $alignment, $generic
+_class_name, $class_name, $generic_race, $race, $gender, $experience,
+ $strength, $dexterity, $constitution, $intelligence, $wisdom, $chari
+sma) = qw(test) x 17;
%general_information = (
"class(es)" => $class_name,
alignment => $alignment,
race => $race,
gender => $gender,
);
%ability_scores = (
strength => $strength,
dexterity => $dexterity,
constitution => $constitution,
intelligence => $intelligence,
wisdom => $wisdom,
charisma => $charisma,
);
sub list_loop {
my $hash_ref = shift;
print "<ul>\n";
for my $key (keys(%$hash_ref)) {
my $value = $hash_ref->{$key};
print "\t<li><strong>".ucfirst $key.":</strong> ".$value."</li>\n"
+;
}
print "</ul>\n";
}
print qq{<h2><a href="$filename" id="$id_name">$first_name $last_name<
+/a></h2>\n};
list_loop(\%general_information);
list_loop(\%ability_scores);