39 lines
1.4 KiB
Plaintext
39 lines
1.4 KiB
Plaintext
From: tim_one at email.msn.com (Tim Peters)
|
|
Date: Sun, 25 Apr 1999 22:26:03 -0400
|
|
Subject: converting perl to python - simple questions.
|
|
In-Reply-To: <aahzFArupt.JE2@netcom.com>
|
|
Message-ID: <000101be8f8c$21a1d540$d5a02299@tim>
|
|
Content-Length: 1073
|
|
X-UID: 1502
|
|
|
|
[about Perl "if (defined($x{$token})"]
|
|
|
|
[Tim sez "under the probably-correct theory that the Perl is just
|
|
asking "does hash 'x' have key 'token'?"]
|
|
|
|
[Aahz Maruch]
|
|
> Try "definitely wrong theory" ;-). In Perl, exists($x{$token}) is
|
|
> precisely equivalent to Pyton's x.has_key(token), and you can either use
|
|
> defined($x{$token}) or $x{$token}!=undef to make sure that a value
|
|
> exists for that key. Thing is, in Perl you can go straight to checking
|
|
> the value because a non-existant key is not an error.
|
|
>
|
|
> (I won't quite call myself a Perl expert, but I'm pretty close to an
|
|
> expert on Perl hashes.)
|
|
|
|
But most Perl programmers aren't, and I've suffered thru enormous piles of
|
|
Perl code that used "defined" where "exists" was appropriate. That's where
|
|
my "probably" comes from: not talking about what the language does, but
|
|
what the programmer probably *intended*. In the absence of more information
|
|
about what the original script does, my guess is still that the author
|
|
*intended* "exists" == has_key.
|
|
|
|
not-all-perl-code-is-well-written<wink>-ly y'rs - tim
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|