Tanktalus,

If I knew you a bit better, I would kiss you all over the face. The best I can do is give you some zen-cookies. You answered the big question I didn't know to ask, what was the proper hashref. This is what happens when one leaves a script for a long while and comes back. Without semantic names, one forgets what is what. So, I was left with a whole bunch of letters that were meaningless and not knowing what was doing what, because I am still not good at this. Use this as a cautionary tale about nonsemantic variable names.

I still couldn't get it to dump the big hash tied up, but that is okay. I don't need it.

Here is the script that works!

#!/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_charac +ters.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 "<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"; } 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 intelli +gence wisdom charisma) ); print qq{<h2><a href="$hr->{filename}" id="$hr->{id_name}">$hr->{fir +st_name} $hr->{last_name}</a></h2>\n}; list_loop(\%general_information); list_loop(\%ability_scores); }

While you are not a fan or repetition, I am not that big a fan of sprawl. I hope you don't mind.

Have a nice day!
Lady Aleena

In reply to Re^4: How to set variable names using Text::CSV? by Lady_Aleena
in thread 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.