in reply to help with counters in perl

The problem is that it's not finding the proper values you initialized to 0 in the 'declare variables' section.

It's complaining about 33 & 34, the last two lines in the following code block (if you exclude the close brace):

foreach my $rec (@records) { chomp($rec); ($game, $commercial) = split(/,/, $rec); $game_count{$game} = $game_count{$game} + 1; $comm_count[$commercial] = $comm_count[$commercial] + 1; }

Since I see that you initialized 'Great','Boring', and 'None' in the %game_count hash, and also the first 4 values in the @comm_count array, it must be that it's reading values from your record file that are outside that set of indices. Maybe there are uncapitalized 'great' entries, or perhaps a vote for commercial 10?

What's the file look like? That's the next step.

Replies are listed 'Best First'.
Re^2: help with counters in perl
by student in perl/cgi (Initiate) on May 17, 2005 at 11:51 UTC

    Ok, I have narrowed it down to the array element is picking up the array Budweiser[1] and MasterCard [3]. I use the -w at the Command Prompt and it says;

    <CODE> Vote for your favorite Super Bowl commercial:
    Budweiser 1
    FedEx 0
    MasterCard 1
    Pepsi 0

    But rec file shows this:

    <CODE> None,2 <CODE>

    The hash and the rec file are correct. How do I get the commercial count to execute correctly?

      The tags are < code > and < /code >, not < CODE > ... < CODE >
      Also, if you had the tags correct, then the < strong > ... < /strong > tags would not have worked within the block.

      Update: Have you tried adding the print statements I suggested in the FP?