davorg has asked for the wisdom of the Perl Monks concerning the following question:
Am I missing something obvious here?
#!/usr/bin/perl -w use strict; package Tie::Hash::Test; use Tie::Hash; use vars qw(@ISA); @ISA = 'Tie::StdHash'; 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.
Any clues?
--
"Perl makes the fun jobs fun
and the boring jobs bearable" - me
Edited 2001-05-24 by Ovid
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: wantarray and Tied Hashes
by Vynce (Friar) on May 24, 2001 at 15:02 UTC | |
by davorg (Chancellor) on May 24, 2001 at 15:09 UTC | |
by tye (Sage) on May 24, 2001 at 23:31 UTC | |
by Vynce (Friar) on May 26, 2001 at 03:04 UTC | |
Re (tilly) 1: ttwantarray/tt and Tied Hashes
by tilly (Archbishop) on May 24, 2001 at 18:10 UTC |