On Thu, May 24, 2001 at 11:28:27AM +0100, Cross David - dcross wrote:

> package Tie::Hash::Test;
> 
> sub FETCH {
>   print "wantarray is ", wantarray ? "true\n" : "false\n";
>   return $_[0]->{$_[1]};
> }
> 
> package main;
> 
> my %h;
> tie %h, 'Tie::Hash::Test';
> 
> %h = (one => 1, two => 2);
> 
> my $scalar = $h{one};
> my @array = $h{two};
> 
> This prints out "wantarray is false" on both accesses. To me, this implies
> that Perl is doing something strange behind the scenes and is forcing the
> FETCH call to always be in scalar context, when I'd expect the second call
> to be evaluated in list context.

FETCH will indeed be called in scalar context.  You can only store scalars
as hash values, and so you will never want to get an array out of them.

Even if you do:

my @array=@h{@multiple_keys}

FETCH will still be called once for each key, in scalar context.

-- 
David Cantrell | [EMAIL PROTECTED] | http://www.cantrell.org.uk/david/

  Rip, Mix, Burn, unless you're using our "most advanced operating system
   in the world" which we decided to release incomplete just for a laugh

Reply via email to