develooper Front page | perl.perl5.porters | Postings from April 2018

Re: [perl #133109] push on scalar forbidden: why?

Thread Previous | Thread Next
L A Walsh
April 20, 2018 01:37
Re: [perl #133109] push on scalar forbidden: why?
Message ID:
Dan Book via RT wrote:
> On Thu, Apr 19, 2018 at 6:09 PM, L A Walsh <> 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

Only functions that require an ARRAY *XOR* HASH could take undef.  Off 
hand, I
can't think of a function that would autovivify a HASH.

Does that clarify the intent of my proposal?  It may be the case that
my proposal is not the same as what was implemented before (I never used
it), but only a subset that is deterministic.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About