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

Discussion in 'Perl Misc' started by ernestm@mindspring.com, Jan 30, 2006.

  1. Guest

    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
    , Jan 30, 2006
    #1
    1. Advertising

  2. Ch Lamprecht Guest

    Re: "Pseudo-hashes are deprecated" error and accessing a hash ofhashes

    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//"
    Ch Lamprecht, Jan 30, 2006
    #2
    1. Advertising

  3. Paul Lalli Guest

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

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

    Paul Lalli
    Paul Lalli, Jan 30, 2006
    #3
  4. Guest

    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
    , Jan 31, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    517
    red floyd
    Nov 10, 2011
  2. Steven Hirsch

    Iterating over a hash of hash of hashes

    Steven Hirsch, Aug 19, 2008, in forum: Ruby
    Replies:
    0
    Views:
    150
    Steven Hirsch
    Aug 19, 2008
  3. Scott  Gilpin
    Replies:
    2
    Views:
    218
  4. Perl Learner

    Hashes of hashes or just one hash ?

    Perl Learner, Jun 8, 2005, in forum: Perl Misc
    Replies:
    11
    Views:
    211
  5. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    210
Loading...

Share This Page