in reply to Adding data to hashes & comparing

I'm not entirely sure, but I have the feeling you could do better with fewer lists and more hashes. In my experience, the only time a list/array is better than a hash is if the order of the items is important and you really don't have a usable key OR you're making a hash where multiple items have the same key, in which case you might want to use a hash of lists. Certainly, if you're going to search for items in the data structure, use a a hash. If you want to make a list of things and later check if something is in that list, don't make it with an array, make it with a hash where all the values are just 1, or something like that. It's easier and faster. I'm sure that's a massive overgeneralization.

I don't know how many times I've said "Okay, this should really be a list" and then later turned it into a hash.

Instead of making a list of all your hashes, make a hash and use the value you want to compare as the key. Then you can just do something like if ( $hash_1{$foo} eq $hash_2{$foo} )....

Replies are listed 'Best First'.
Re^2: Adding data to hashes & comparing
by hallikpapa (Scribe) on Mar 31, 2009 at 15:52 UTC
    Thanks for the tips. I believe I am close, but not there yet. This section of code doesn't seem to be operating as I expect?
    if (%data) { # We have data to process while( my ($key, $value) = each(%data) ) { if($key =~ '%{User-Agent}i\""') { $userAgent = $value; } if($key =~ '%t') { $date = $value; } } $aRequests = $hRequests{$date}{$userAgent}; push @$aRequests, \%data; }


    I am using eclipse and even though I breakpoint and see the hash keys %{User-Agent}i\"" & %t, those if statements are never satisfied. It loops through the entire hash, but the $key never changes from %{Referer}i.

    What am I doing wrong?

      Are you sure it's not that the pattern doesn't match?