in reply to Surprising whitespace behavior

Not knowing which post to reply to...

So now that we've determined that "$ x" behaves differently from "@ x", why stop there?

DB<1> $x = 'DollarX' DB<2> @x = 'a'..'g' DB<3> %x = qw(1 a 2 b 3 c) DB<4> sub x { print "This is Sub x\n" } DB<5> p "<$x> <@x> <%x> <&x>" <DollarX> <a b c d e f g> <%x> <&x> DB<6> p "<$ x> <@ x> <% x> <& x>" <DollarX> <@ x> <% x> <& x> DB<7> p "$ #x" Final $ should be \$ or $name at (eval 12)[C:/Perl/lib/perl5db.pl:17] +line 2, within string syntax error at (eval 12)[C:/Perl/lib/perl5db.pl:17] line 2, near "} +"$ #x""
So "$ x" is the only one this works for, and it breaks for "$ #x", even though that looks like a scalar (and it probably shouldn't break!). But "$ x[0]" produces "a", and so does "$ x{1}".

I'm sure there's some Good Reason Why This Is So...Perhaps it's easy to figure out what to do with "$x", but there are more options with "@x". The string interpolation aspect of ignoring whitespace was probably not updated when "@x" interpolation was added. [I secretly hoped Merlyn would have the skinny on that -- but I'm sure he would have said so.]

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: Surprising whitespace behavior (significant whitespace++)
by tye (Sage) on Sep 23, 2004 at 19:53 UTC

    I think "$ x" should be "\$ x". I have no problem with double-quote interpolation being more strict than the equivalent Perl code (it already is and this one more case would be an improvement).

    I think it is just a matter of the original implementor(s) (way back in Perl2) deciding to support ignoring such whitespace (to match how Perl works outside of double quotes) and the more recent implementor(s) (p5p) not even thinking of supporting such a strange construct (and so not worrying about making them consistent).

    - tye