in reply to Re: add text to a string
in thread add text to a string

you're right, sorry for that. The problem was that something like this
$self->{blablabla}->{more_bla}->{and_more}->[$_] = "a".$self->{blablab +la}->{more_bla}->{and_more}[$_];
doesn't look verywell.
So I think the solution with substr looks much better!!
But still, if something like '.=' exists, one would expect something simular for adding text to the front of a string!

Luca

Replies are listed 'Best First'.
Re^3: add text to a string
by blazar (Canon) on May 30, 2006 at 12:24 UTC

    Well, in addition to all that has been said thus far, you can also do

    $_ = 'a' . $_ for $self->{blablabla}->{more_bla}->{and_more}->[$_];
Re^3: add text to a string
by davido (Cardinal) on May 30, 2006 at 15:14 UTC

    You're right. That looks horrible. Maybe you should grab your value into a sensibly named lexical first, and reassign later so the whole operation looks clearer:

    my $entity = $self->{blablabla}{more_bla}{and_more}[$_]; $entity = 'a' . $entity; $self->{blablabla}{more_bla}{and_more}[$_] = $entity;

    This is marginally less efficient, particularly if the string in question is really big. But it deobfuscates what's going on. It would be really easy to miss the concatenation if you're reading through your code. But if you unpack your value into some sensibly named lexical before performing operations on it, the resulting code will be much easier to read.


    Dave