in reply to Strange behaviour with Arrays and print?

Actually, I'd say it's pretty strange indeed
perl -E 'my @a=qw(10 20 30); say "@a!"; say @a . "!"'
Output:
10 20 30! 3!
I always thought that things like "$foo\n" were compile-time shortcuts for $foo . "\n". Apparently not, at least not for arrays...

Replies are listed 'Best First'.
Re^2: Strange behaviour with Arrays and print?
by AnomalousMonk (Archbishop) on Jul 12, 2014 at 14:06 UTC

    But in the spirit of your example code, the compiler might proceed something like:
    Source   "@a\n"
    Becomes  "@a" . "\n"
    Becomes  join($", @a) . "\n"
    Becomes  "10 20 30" . "\n"
    Becomes  "10 20 30\n"
    with  join($", @a) (or its runtime equivalent) still providing list context to the array.

      You're right, of course. Also, it appears that Perl has different overloads for for string concatenation and stringification. Interesting... I never knew that.