in reply to Re: Is space supposed to be ignored between a sigil and its variable name?
in thread Is space supposed to be ignored between a sigil and its variable name?

Unless you 'wanted' to interpolate

my $bar = "$ foo and $cake";

Or a more likely example

my $bar = "$ $total_foo_dollars";

I had no idea that spaces in quotes could be abused this way and it just feels so wrong.

How about

my $foo = ['a', 'b', 'c']; my $bar = "$ foo -> [2]";

vs

my $foo = ['a', 'b', 'c']; my $bar = "$foo->[2]";

Before reading this thread I would have a clear answer for what the result of $bar would be in each case. After reading this thread I had a less clear different answer. And after actually testing the code I can see now that I was wrong in all my assumptions. Now I've got a nagging feeling that I should review all my code for unintended quoting results.

Replies are listed 'Best First'.
Re^3: Is space supposed to be ignored between a sigil and its variable name?
by almut (Canon) on Apr 18, 2009 at 22:01 UTC

    What do those print, and why?  (Without cheating and running the code! :)

    #!/usr/bin/perl $foo = "foo"; print "1: $ $ $ foo\n"; print "2: $ $$ foo\n"; print "3: $ $$foo\n"; print "4: $$$foo\n";
      Excellent exercise :D

      Okay, okay, I admit it - I got 1 right, but the other 3 flummoxed me, so I ... well I cheated!!

      Now I know what they all print - all that's left to do now is the hard part i.e. RTFM & work out why ...

      A user level that continues to overstate my experience :-))