submersible_toaster has asked for the wisdom of the Perl Monks concerning the following question:

OK , it's petty and odd but this has piqued my curosity enough that I just cannot let go. After reading Perl6 Headaches? and the associated discussion of the . and the _ , specifically how the new concatenation operator would need to be de-ambigufied (sp.) with a leading whitespace ie $foo _ $bar , or $foo _$bar.

So what? Well lets come back to perl5 concatenation.
print $foo.$bar
does what I expect concatenation to do.
BUT print $foo.bar.how.is.my.syntax

I would have expected to be a syntax error, admittedly it spews warnings if -w is specified , and it certainly won't pass strict.

The question? Could someone explain what . is doing to it's left and right values, throwing a theoretical qq/ / around them? Of course if a sub bar {} had been declared then .bar concatenates the return value of &bar().


I can't believe it's not psellchecked

Replies are listed 'Best First'.
Re: Syntax Explanation PLs
by Paladin (Vicar) on Jan 07, 2003 at 05:46 UTC
    From perldata: "A word that has no other interpretation in the grammar will be treated as if it were a quoted string.". So those bare words in your print (except for my which causes a compolation error) are treated as if you wrote:  print $foo.'bar'.'how'.'is'.'the'.'syntax'
Re: Syntax Explanation PLs
by djantzen (Priest) on Jan 07, 2003 at 05:52 UTC

    Running it through B::Deparse reveals that you're close:

    perl -MO=Deparse -e '$foo = "blarny!"; print $foo.bar.baz.quux;'

    yields:

    $foo = 'blarny!'; print $foo . 'bar' . 'baz' . 'quux'; -e syntax OK

    And prints "blarny!barbazquux".

      /me makes mental note to investigate B::Deparse sometime soon. Interestingly enough, and this is now way beyond useful.

      $foo = 'hmmm'; bar = 'why?'; print $foo.bar.me
      Deparses as
      $foo = 'grrr'; do bar = 'why?'; print $foo . 'bar' . 'me';
      Of course they break in different ways. do bar = 'why?' dies with a compilation error. Can't modify do "file" in scalar assignment
      bar = 'why?' Gets through with a warning, but when used with . results in a error : Undefined subroutine &main::bar.
      My presumption is 'bar=' does something ugly to the symbol table - and why not? its pretty cruel use of syntax, sadly it's also an easy typo.

      use strict #or die screaming.$!