Hi Monks, I'd greatly appreciate any help on this piece of code. I'm expecting the script to display the value following each Report Type (Attendance Sales Tickets Fans). For some reason it keeps displaying the value from the Attendance Report only. The Data Dumper looks to have the correct key-> value pair so I can't figure out why looping and printing is not giving me the correct value for the key.

#!/usr/bin/env perl use Data::Dumper; my @report_name = qw(Attendance Sales Tickets Fans); while (<DATA>) { my %by_report = split ' '; print Dumper(\%by_report); for (@report_name) { print "report_name is: $_\n"; if ( exists ($by_report{$report_name[$_]} ) ) { print "$_ Report is: $by_report{$report_name[$_]}\n"; } else { print "No data for $_ Report\n"; } } } __DATA__ Attendance 7424 Sales 7074 Tickets 350 Fans 109 Attendance 321541 Sales 321508 Tickets 31 Fans 101 Attendance 9208 Sales 9208 Fans 102 Attendance 9832 Sales 9829 Tickets 3 Fans 106 Attendance 1559058 Sales 1503174 Tickets 55404 Fans 104

Any help is much appreciated. Thank you.


In reply to Dereferncing Hash Not Working by dirtdog

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.