"Robert Arnold" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello all,
>
<snip />
>
> while ((my $key, my $value) = each %$response) {
>        if ($key eq "OrgName")
>                 {
>                 print "$range $value\n";
>                 #short circuits the while loop...i think?
>                 last;
>                 }
> } #end of while
>
>
> } #end of foreach
>
>
>
> NOW, my question is this: If I can traverse the hash and look for a key
> which is equal to "OrgName", why can't I simply print:
$response{'OrgName'} ?
> It just seems there should be a quicker, simpler way than having to
> traverse the whole hash.
>
> I'm guessing the answer has something to do with
referencing/dereferencing,
> which is a new subject for me. The perldoc says that $response is "a
> reference to a hash containing all information provided by the whois
> registrar".
>

$response{'OrgName'} looks up a key in the hash %response. In your program
there is no hash called %response. $response is a scalar variable that
stores a reference to your object. To get at the key titled 'OrgName' you
have to first dereference $response. this can be accomplished by:

${ $response }{OrgName}

or the more readable syntax:

$response->{OrgName}

Note:

C:\WINDOWS\Desktop>perl
$res = {
  OrgName => 'Foo Inc.',
};

print( ${ $res }{OrgName}, "\n" );
print( $res->{OrgName}, "\n" );
Ctrl-Z
Foo Inc.
Foo Inc.

Todd W.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to