Bad, bad title, I know ;) (Not sure what happened the last time I tried to post this. . .) I'm trying to publish stats for our hockey league on a web page. Early in the program, I load a hash with the names of each team, and an abbreviation for each. For example:
Abv Team ------------------ WSH Washington BUF Buffalo ANA Anaheim CMB Columbus NJ New Jersey ATL Atlanta MTL Montreal
To make sure I loaded the hash correctly, I used the following code to dump the contents of the hash to a page:
for my $key (keys %teams) { print $key . " - " . $teams{$key} . "<BR>\n"; }
Where %teams is obviously the list of teams, where the abbreviation is the key and the name of the team is the value. The above code did what it was intended - it printed a list of all 30 teams in the league.

The next step was to read through a comma-delimited file (using DBI and DBD::CSV) with the desired stats (what's above and below this works fine):

while (my $row = $sql->fetchrow_hashref) { my %row_data; $team = $row->{'Teams'}; $row_data{TEAM} = $teams{$team}; $row_data{GP} = $row->{'GP'}; $row_data{W} = $row->{'W'}; $row_data{L} = $row->{'L'}; $row_data{T} = $row->{'T'}; $row_data{OTL} = $row->{'OTL'}; $row_data{P} = $row->{'P'}; push(@table, \%row_data); }
@table is an array I hand off to HTML::Template to build a result table. The table prints as intended, however, all of the team names are blank. But if I change this:
$row_data{TEAM} = $teams{$team};
to this:
$row_data{TEAM} = $team;
I get the abbreviation for the team I intended. Even stranger, if I change the line to this:
$row_data{TEAM} = $teams{"NYR"};
I get NY Rangers to show up for all 30 teams. Why are my hash values coming back blank?

I tried doing a super-search for the above problem and didn't seem to turn up anything. Can anybody shed some light on this? It's really frustrating me. I had to put down perl for too long a time (how dare work interfere with something fun ;) and thought I'd get back into the swing of things with something easy.

Thanks in advance,
MrCromeDome


In reply to Need help hashing this out. . . by MrCromeDome

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.