On 10/23/06, Adriano Ferreira <[EMAIL PROTECTED]> wrote:
On 10/23/06, Romeo Theriault <[EMAIL PROTECTED]> wrote:
> Thank you Adriano, that works nicely after I added:
>
> use Memoize::AnyDBM_File;
>
> before that I was getting this error:
>
> AnyDBM_File doesn't define an EXISTS method at ....

I had not payed much attention to the fact that your code were using
ties rather than simple hashes. I did not know either AnyDBM_File ties
missed EXISTS method (if it had an EXISTS, it should have been
transparent to you). But there must be some good reason, like not
caching by default to avoid performance penalties.

> But I do have a question about your solution.
> > foreach $key_h (keys %hash) {
> >            print "$key_h\n" unless exists $dbmhash{$key_h};
> > }
>
> I don't understand why $dbmhash{$key_h} refers to the key whereas
> earlier in  the code when I do:
>
> if ($hash{$key_h} <= 788) {
>         $dbmhash{"$key_h"} = $hash{$key_h};
> }
>
> $hash{$key_h} <= 788   is looking at the key value?

* A simple thing like $hash{foo} looks at the value of %hash stored at
"foo" value.
* $hash{'foo'} does the same.
* $hash{"foo"} does the same.
* $hash{$foo} uses what's stored at $foo as the key.
* $hash{"$foo"} uses the result of "$foo" (an interpolation) as the key

But if $key_h is a string, "$key_h" is just the same as $key_h.

Ok, thank you, I hadn't noticed the distinctions before.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to