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.

Script 1

#!/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); }

Script 2

#!/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);
Have a nice day!
Lady Aleena

In reply to How to set variable names using Text::CSV? by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.