Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > "Pseudo-hashes are deprecated" error and accessing a hash of hashes

Reply
Thread Tools

"Pseudo-hashes are deprecated" error and accessing a hash of hashes

 
 
ernestm@mindspring.com
Guest
Posts: n/a
 
      01-30-2006
OK, so I see that this is a Perl 5.8 change. I am getting this
"Pseudo-hashes are deprecated" error while following the Camel Book v3
and trying to generate a count of items in a hash of hashes thus:

scalar(keys %{ $logips{$key} } )

Basically I'm parsing a Web log file and am trying to keep a list of
unique IPs that visited each page (modifying Perl Cookbook recipe 4.6)
thus:

my %logips=();
my %logipseen=();
foreach $snifferlog (@ARGV) {
blah blah blah;
push (@{ $logips{$logfile} }, $logip) unless (
$logipseen{ $logfile }{ $logip } )++;
}
foreach $key (@logfiles) {
print scalar(keys %{ $logips{$key} } );

So $logips{$key} should have a hash of all the unique IPs in it, I just
want a quick count, but I'm having trouble with the hash of hash
syntax. Apparently the older syntax in the camel book's not good any
more and I've fiddled aroudn with this a while and read Web tutorials
on hashes of hashes without luck. Any help welcome!

Thanks,
Ernest

 
Reply With Quote
 
 
 
 
Ch Lamprecht
Guest
Posts: n/a
 
      01-30-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) schrieb:
> OK, so I see that this is a Perl 5.8 change. I am getting this
> "Pseudo-hashes are deprecated" error while following the Camel Book v3
> and trying to generate a count of items in a hash of hashes thus:
>
> scalar(keys %{ $logips{$key} } )
>
> Basically I'm parsing a Web log file and am trying to keep a list of
> unique IPs that visited each page (modifying Perl Cookbook recipe 4.6)
> thus:
>
> my %logips=();
> my %logipseen=();
> foreach $snifferlog (@ARGV) {
> blah blah blah;
> push (@{ $logips{$logfile} }, $logip) unless (

------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
that's a hash of arrayrefs
> $logipseen{ $logfile }{ $logip } )++;
> }
> foreach $key (@logfiles) {
> print scalar(keys %{ $logips{$key} } );

print scalar @{ $logips{$key} };
>
> So $logips{$key} should have a hash of all the unique IPs in it, I just
> want a quick count, but I'm having trouble with the hash of hash
> syntax. Apparently the older syntax in the camel book's not good any
> more and I've fiddled aroudn with this a while and read Web tutorials
> on hashes of hashes without luck. Any help welcome!
>
> Thanks,
> Ernest
>

HTH Christoph

--

perl -e "print scalar reverse q/(E-Mail Removed)/"
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      01-30-2006
(E-Mail Removed) wrote:
> OK, so I see that this is a Perl 5.8 change. I am getting this
> "Pseudo-hashes are deprecated" error while following the Camel Book v3
> and trying to generate a count of items in a hash of hashes thus:
>
> scalar(keys %{ $logips{$key} } )
>
> Basically I'm parsing a Web log file and am trying to keep a list of
> unique IPs that visited each page (modifying Perl Cookbook recipe 4.6)
> thus:
>
> my %logips=();
> my %logipseen=();
> foreach $snifferlog (@ARGV) {
> blah blah blah;


Please don't do that. Post a short-but-*complete* script that we can
run by copy and pasting. Based on what you've shown, I have to
conclude that your real problem is within this blah blah blah.

> push (@{ $logips{$logfile} }, $logip) unless (


Where idd $logfile and $logip come from?

> $logipseen{ $logfile }{ $logip } )++;
> }
> foreach $key (@logfiles) {


Where did @logfiles come from? You never declared or added to it
before now.
Are you sure you didn't mean
foreach my $key (keys %logips}
?

> print scalar(keys %{ $logips{$key} } );


> So $logips{$key} should have a hash of all the unique IPs in it


How do you figure that? Above, you said that $logips{$key} is a
reference to an array. You said that when you dereferenced it as an
array:
push (@{ $logips{$logfile} }, $logip)

But now you're trying to use it as a reference to a hash. As a guess,
I'd say this is the cause of your pseudo-hash error. If you want the
number of elements in this array, get it the same way you get the size
of any other array: Evaluate it in scalar context:

print scalar(@{$logips{$key}});

> , I just
> want a quick count, but I'm having trouble with the hash of hash
> syntax. Apparently the older syntax in the camel book's not good any
> more


No. The syntax for getting at your hash-of-hashes has never changed.
It is pseudo-hashes that are being driven out of the language.

> and I've fiddled aroudn with this a while and read Web tutorials
> on hashes of hashes without luck. Any help welcome!


You're going to need to post real code if you want real help. In the
meantime, allow me to suggest you print out your structure with
Data:umper to see what it actually contains.

use Data:umper;
print Dumper(\%logips, \%logipseen);

Paul Lalli

 
Reply With Quote
 
ernestm@mindspring.com
Guest
Posts: n/a
 
      01-31-2006
Thanks Christoph! That fixed me up. Yes, I was doing a hash of lists
and not a hash of hashes, I got confused since I was also doing a hash
of hashes.

Ernest

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Iterating over a hash of hash of hashes Steven Hirsch Ruby 0 08-19-2008 12:34 AM
Hash of hashes, of hashes, of arrays of hashes Tim O'Donovan Perl Misc 5 10-28-2005 05:59 AM
Hashes of hashes or just one hash ? Perl Learner Perl Misc 11 06-09-2005 06:55 AM
Performance Improvement of complex data structure (hash of hashes of hashes) Scott Gilpin Perl Misc 2 08-26-2004 01:02 AM



Advertisments