in reply to Re: redefining string interpolation
in thread redefining string interpolation

return SF->new ("$lhs->{str}$rhs->{str}", $lhs->{list}, $rhs->{list});

Shouldn't the merging of the lists look something like

... return SF->new ( "$lhs->{str}$rhs->{str}", [ map ref($_) eq 'ARRAY' ? @$_ : (), $lhs->{list}, $rhs->{list} ] );

Another issue (which I don't have a solution for) is that what's LHS and RHS seems to vary with the circumstances of the concatenation, i.e. while this

my $name1 = SF->new ('GrandFather', [1, 2, 3]); my $name2 = SF->new (' and Almut', [4, 5, 6]); my $catStr = $name1 . $name2; use Data::Dumper; print Dumper $catStr;

produces (as expected)

$VAR1 = bless( { 'str' => 'GrandFather and Almut', 'list' => [ 1, 2, 3, 4, 5, 6 ] }, 'SF' );

"Name is $name1" (or "Name is " . $name1)  doesn't :

$VAR1 = bless( { 'str' => 'GrandFatherName is ', 'list' => [ 1, 2, 3 ] }, 'SF' );

(note that "Name is " is appended to "GrandFather", not the other way round)

Replies are listed 'Best First'.
Re^3: redefining string interpolation
by GrandFather (Saint) on Nov 28, 2009 at 04:43 UTC

    Changing the SF constructor to:

    sub new { my ($class, $str, @lists) = @_; my @list = map {'ARRAY' eq ref $_ ? @$_ : $_} @lists; return bless {str => $str, list => \@list}, $class; }

    fixes the list concatenation issue. The ordering issue is fixed by changing the first few lines of catSF to:

    sub catSF { my ($lhs, $rhs, $inv) = @_; ($lhs, $rhs) = ($rhs, $lhs) if $inv;

    True laziness is hard work