datannen has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I could really use your help. I am using a funky line in my code to store bad rows of log data:

push @{%Bad_Host_Rows->{dirname($row[1])}->{$row[0]}}, [@row];
row 0 = IP row 1 = path row 2 = date
When I make simple tests with this line, it works perfectly. However, when actually running it in my code I'm getting multiple $VAR1 values in Dumper for the same hashes.

Example:

$VAR1 = {'/testdir/1000/200' => { '12.123.12.12' => [ ['12.123.12.12', + '/testdir/1000/200/index.php', '2004-05-25 00:33:30'], ['12.123.12.12', '/testdir/1000/200/index.php', '2004-05-25 00:33:31'] +] }}; $VAR1 = {'/testdir/1000/200' => { '12.123.12.12' => [ ['12.123.12.12', + '/testdir/1000/200/index.php', '2004-05-25 00:33:34'], ['12.123.12.12', '/testdir/1000/200/index.php', '2004-05-25 00:33:34'] +]}};
Why are my rows not being pushed into the same hash, but sometimes creating copies of themselves?

Thanks for your help.

edit (broquaint): tidied up formatting

Replies are listed 'Best First'.
Re: crazy hashes
by Aragorn (Curate) on May 25, 2004 at 09:13 UTC
    One thing to note is that the "funky line" has a bug. You're using a hash variable as a reference (the %Bad_Host_Rows->{dirname($row[1])} part. Changing this part to $Bad_Host_Rows{$row[1]} will probably fix your problem.

    Recent versions of Perl complain about this problem.

    Arjen

      push @{$Bad_Host_Rows{dirname($row[1])}{$row[0]}}, [@row];
      Changed it to the above and still getting the same results.
      
      More Info:
      After I push all the data onto the hash, I return it using:
      
      return (bless (\%Bad_Host_Rows));
      and retrieve it by using:
      $badrows = $base->get_Bad_Rows(qw/host request fulldatetime/);
      
      
      Then using these lines:
      %hasher = %{$badrows}; print Dumper(\%hasher);
      Thanks again for your help.
        You get a perfectly good hash reference back from get_Bad_Rows(). Why copy it into another hash and then display that?
        $badrows = $base->get_Bad_Rows(qw/host request fulldatetime/); print Dumper($badrows);
        works fine.

        Arjen

Re: crazy hashes
by saberworks (Curate) on May 25, 2004 at 09:09 UTC
    Well, I have noticed that Data::Dumper produces funny results when printing hashes, just like you are experiencing. Try passing it a reference to your hash instead, and it should show up in a nicer format. Instead of all those VAR1s.