in reply to Warnings, and declaring Hashes of Hashes.

You need to ensure that you are testing scalars. %USERLIST->{$USER}->{'TIME'} should be written as $USERLIST->{$USER}->{'TIME'} (note the leading dollar sign). In this case, you're evaluating the entire hash in scalar context. That's going to have unpredictable results.

Cheers,
Ovid

Update: I tested your method of looking up hash elements and it appears to work:

use warnings; my %hash1 = ( test => 3 ); my %hash2 = ( bobby => 15, what => 'thehell' ); print "good\n" if %hash1->{'test'} < %hash2->{'bobby'}; print "good1\n" if $hash1{'test'} < $hash2{'bobby'};
However, it is definitely not how it's usually done and I suspect you'll find that most agree that using the $ first is preferable. Not sure if there are any issues with the other way.

Also, just because you have a particular key in existence does not mean that it's defined.

Make sure that %USERLIST->{...} is changed to $USERLIST{...}.

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid) Re: Warnings, and declaring Hashes of Hashes.
by japhy (Canon) on Nov 30, 2000 at 04:11 UTC
    For reasons that I've never been able to get an answer to, the following syntax is valid:
    @array->[$idx]; %hash->{$key};


    japhy -- Perl and Regex Hacker
      Here's a guess :)

      The -> notation implies a context -- in fact, it implies that whatever to the left is a reference, and whatever is to its right is "owned" by the referred-to object.

      Perl seems pretty smart about context.

      So, in these cases, it interprets the thing to the left as a reference to the object named, and voila, does the right thing, since the "members" are being referred to properly.

      If you try to use ref() on the whole "thing" (hash or array) you won't see it as a reference because it is simply interpreting the "thing" in a scalar context, though.

      Update:
      Looking in perlref there is the cryptic comment:

      . References of the appropriate type can spring into existence if you dereference them in a context that assumes they exist. Because we haven't talked about dereferencing yet, we can't show you any examples yet.

      (See number 6).

      I'm guessing that's the case here.

        The cryptic comment in perlref that you refer to is this behaviour:
        $foo{bar}{baz}; # Assumes $foo{bar} exists and is a hash print ref($foo{bar}); # And lo and behold, it is!
        And I am with japhy on not knowing why this works. Certainly there is nothing I know of about context that would explain it...
Re: (Ovid) Re: Warnings, and declaring Hashes of Hashes.
by BatGnat (Scribe) on Nov 30, 2000 at 02:52 UTC
    now i get this
    Name "main::USERLIST" used only once: possible typo at D:\BIN\SCRIPTS\ +PerlScripts\45daysold\45daysold.pl line 44. Name "main::USER_INFO" used only once: possible typo at D:\BIN\SCRIPTS +\PerlScripts\45daysold\45daysold.pl line 44.
    after chnaging it to this if ( $USERLIST->{$USER}->{'TIME'} < $USER_INFO->{'LastLogon'})