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

E

ernestm

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
 
C

Ch Lamprecht

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
 
P

Paul Lalli

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::Dumper to see what it actually contains.

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

Paul Lalli
 
E

ernestm

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top