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

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

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
April 21, 2018 19:57
Subject:
Re: [perl #133109] push on scalar forbidden: why?
Message ID:
20180421195706.GJ2839@iabyn.com
On Sat, Apr 21, 2018 at 06:17:09PM +0100, Philip R Brenan wrote:
> *Push gets its array either directly or via a reference. *In this example:
> 
> push $r, 3
> 
> would affect only $r, not @real_a,  because no  array dereference would be
> implied or performed.

Then you've just broken overloading. For example, suppose someone writes
this innocuous  method:

    sub push_foo {
        my ($self, $array_ref) = @_;
        push $array_ref, $self->foo;
    }

this method works exactly as documented and expected, until the day
someone passes an overloaded scalar as an arg to it, then finds that
the overloading is being quietly ignored.

-- 
That he said that that that that is is is debatable, is debatable.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About