in reply to Perl Concatenate vs Append Operator

Hi,

just as an addition. Compare the output of:

perl -MO=Terse -E'my $str = "McA"; $str = $str . " ";'

and

perl -MO=Terse -E'my $str = "McA"; $str .= " ";'

So the internal way of handling this (tried with Perl 5.10.1) is the same.

Regards
McA

Replies are listed 'Best First'.
Re^2: Perl Concatenate vs Append Operator
by Anonymous Monk on Aug 19, 2014 at 18:08 UTC

    But!

    perl -MO=Terse -E'our $str; $str = $str . " ";'
    and
    perl -MO=Terse -E'our $str; $str .= " ";'

      Hi,

      I'm so used to lexical variables that I didn't think about that. That's really interesting.

      Thank you for that insight.

      McA

Re^2: Perl Concatenate vs Append Operator
by Laurent_R (Canon) on Aug 19, 2014 at 21:32 UTC
    I just tried it on Perl 5.14, I do not get exactly the same thing with your two one-liners:
    $ perl -MO=Terse -E'my $str = "McA"; $str = $str . " ";' LISTOP (0x600153910) leave [1] OP (0x60007fdb0) enter COP (0x60006e3c0) nextstate BINOP (0x6001f1ea0) sassign SVOP (0x60006e2e0) const [3] PV (0x6001f2c08) "McA" OP (0x60006f890) padsv [1] COP (0x6001f7fe0) nextstate BINOP (0x6001f7fa0) concat [1] OP (0x600153980) padsv [1] SVOP (0x6001f7f60) const [4] PV (0x6001f2b78) " " -e syntax OK $ perl -MO=Terse -E'my $str = "McA"; $str .= " ";' LISTOP (0x600153910) leave [1] OP (0x60007fdb0) enter COP (0x60006e3c0) nextstate BINOP (0x6001f1ea0) sassign SVOP (0x60006e2e0) const [3] PV (0x6001f2c08) "McA" OP (0x60006f890) padsv [1] COP (0x6001f7f60) nextstate BINOP (0x6001539c0) concat [2] OP (0x600153950) padsv [1] SVOP (0x600153980) const [4] PV (0x6001f2b78) " " -e syntax OK
    There are some differences on the ante-penultimate and penultimate lines. But I am not really able to assess whether the difference is significant. The Deparse module also gives different output for these two lines in Perl 5.14.