in reply to [Solved]: How to append a string at the end of another string using substr

This works for me:

Update: if you don't know the length of the string, use  length($string) :-)

my $string1 = "Hello"; my $string2 = " World"; substr($string1, length($string1), 1, "$string2"); print "$string1\n";
The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: How to append a string at the end of another string using substr
by AnomalousMonk (Archbishop) on Jul 14, 2015 at 18:35 UTC

    Or maybe, since Perl300 is happy to use the concatenation operator:

    c:\@Work\Perl>perl -wMstrict -le "my $string1 = 'Hello'; my $string2 = ' World'; ;; $string1 = substr($string1, 0) . $string2; print qq{'$string1'}; " 'Hello World'


    Give a man a fish:  <%-(-(-(-<

      Thank you: 1nickt, toolic, AnomalousMonk. Your replies work for me. I'll choose one that will suit best for my need.