in reply to A dereferencing problem

It appears you have already been sufficiently answered, but I have a quick nitpicky comment that will probably get me some giggle-inducing downvotes. In your question, you say:

I have a sub routine which returns a HASH reference to a data structure as follows

$myhash{$key}->($value1, $value2)

I'm not sure if you meant that %myhash contains an array reference at $key, but your code seems to indicate that it's actually a code reference. The syntax you have is exactly that for calling a code reference, and passing $value1 and $value2 as arguments to it.

Replies are listed 'Best First'.
Re: Re: A dereferencing problem
by periapt (Hermit) on Apr 29, 2004 at 19:03 UTC
    It does sort of look that way, doesn't it? I think the code suggests the HoA structure though. If he were using code references, the assignment line would be more like  ($value1, $value2)= &{$ref->{$key}} with the assumption that the referenced function returned a list. If the referenced function returned a pointer to an array then the assignment would be  ($value1, $value2)= @{&{$ref->{$key}}} which is getting decidedly unlovely in appearance.

    PJ
      It does sort of look that way, doesn't it?

      No, it doesn't look that way, it is that way. I was pretty sure he meant that there was an array reference at that key, but trying to point out that the actual syntax of his "example" was something completely different (that is, calling a coderef stored in the hash).

      Incidentally, your two examples can be written as ($value1, $value2) = $ref->{$key}->() and ($value1, $value2) = @{ $ref->{$key}->() }, which I find more readable.