develooper Front page | perl.perl5.porters | Postings from June 2019

Re: Making join() respect string-concat operator

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
June 11, 2019 11:22
Subject:
Re: Making join() respect string-concat operator
Message ID:
20190611112222.GM4761@iabyn.com
On Mon, Jun 10, 2019 at 10:22:09AM -0400, Matthew Horsfall (alh) wrote:
> On Wed, Jun 5, 2019 at 5:30 AM Dave Mitchell <davem@iabyn.com> wrote:
> > At the moment its reasonably clear that where you explicitly use the '.'
> > operator (and double-quoted strings, which are syntactic sugar for
> > concatenation) you should expect concat overloading to be honoured.
> [...]
> >
> > We should keep a clear distinction between:
> >
> >     concat operator '.' appears in the source code
> >
> > and
> >
> >     perl concatenates two strings for some reason.
> 
> To me "" seems like the latter, not the former.
> 
> This is probably documented somewhere but I find it surprising that
> "$foo" calls concat overloading on $foo before string overloading.

I'm not sure I follow. "$foo" calls '""' overloading, not '.':

This:

    use overload
        '""' => sub { print "STRFY($_[0][0])\n"; $_[0][0] },
        '.'  => sub { print "CONCAT$_[0][0], $_[1][0])\n";
                        bless [ $_[0][0] . $_[1][0] ] }
        ;

    my $s = bless [ "foo" ];
    my $t = "$s";

outputs:

    STRFY(foo)


-- 
Diplomacy is telling someone to go to hell in such a way that they'll
look forward to the trip

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