dirtdog has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dereferncing Hash Not Working
by toolic (Bishop) on Jun 08, 2017 at 20:39 UTC | |
|
Re: Dereferncing Hash Not Working
by kennethk (Abbot) on Jun 08, 2017 at 20:43 UTC | |
by dirtdog (Monk) on Jun 08, 2017 at 20:51 UTC |