On Thu, Apr 19, 2018 at 06:37:26PM -0700, L A Walsh wrote: > Dan Book via RT wrote: > > On Thu, Apr 19, 2018 at 6:09 PM, L A Walsh <perl-diddler@tlinx.org> wrote: > > ... > > > > > The manpage shows: > > > Functions for real @ARRAYs > > > "each", "keys", "pop", "push", "shift", "splice", "unshift", > > > "values" > > > > > > Functions for real %HASHes > > > "delete", "each", "exists", "keys", "values" > > > > > > > each, keys, and values work on both arrays and hashes. As does exists and > > delete, technically. > > > > -Dan > > > Yes...for dereferencing to work in this case, the scalar would have to > hold either an ARRAY or HASH reference. It really makes no sense to try > to use "each", "keys" nor "values" on a a scalar that has value 'undef'. > It would make no sense and would (should) generate an error as it does > now. But when you have a scalar reference which is overloaded, perl can't know what overload method to call in those cases. For example: use overload '@{}' => sub { print "array deref\n" ; return \@real_a }, '%{}' => sub { print "hash deref\n" ; return \%real_h }, ; my $r = bless []; push $r, 3; # prints "array derdef", modifies @real_a $r->{foo} = 'bar'; # prints "hash derdef", modifies %real_h @k = keys $r; # what overload method does this call? What should perl do in the last case? -- The optimist believes that he lives in the best of all possible worlds. As does the pessimist.Thread Previous | Thread Next