in reply to Why does this code think I'm trying to use symbolic references?

I know how to work around it; but for the life of me I cannot see why I need to?

This is hairy. It is one case where whitespace matters in perl.

Two things are going on here:

  1. resolution of the args to print as indirect object notation vs. resolvable term
  2. determination of the meaning of '+' in '$n +4'

use strict; $n = 1000; $\=$/; print $n +4; # indirect object notation, + is sign marking 4 as posit +ive (unary plus) print $n + 4; # $n + 4 is addition, result is printed print +$n +4; # unary + prevents $n from being interpreted as file han +dle, 1004 is printed print ($n +4); # same as case 1 print ($n + 4); # same as case 2 print+($n +4); #same as case 3
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
  • Comment on Re: Why does this code think I'm trying to use symbolic references?
  • Download Code

Replies are listed 'Best First'.
Re^2: Why does this code think I'm trying to use symbolic references?
by BrowserUk (Patriarch) on Jun 13, 2016 at 12:37 UTC
    This is hairy.

    Indeed. I'm just amazed that I have never encountered this before. I regularly hit this one:

    $x = 10; print ( $x + 1 ) / 3;; 11

    But never to my recollection the OP problem.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.
Re^2: Why does this code think I'm trying to use symbolic references?
by Your Mother (Archbishop) on Jun 13, 2016 at 14:54 UTC

    I understand it is strange to hit whitespace issues in Perl (where weirdness like my$   n = 1 is legal) but this seems sensible and, this part, not hairy; I'd be alarmed if it worked any differently. Only the print(list) and file handle stuff is surprising and Perl users learn those issues, I hope, pretty early. +4 looks, like -4, unambiguously signed. Maybe the negative reads more clearly since we're used to never seeing the positive.

    print $n -4;
      I understand it is strange to hit whitespace issues in Perl (where weirdness like my$   n = 1 is legal) but this seems sensible and, this part, not hairy; I'd be alarmed if it worked any differently.

      Yes, yes and yes; and yes. My statement is ambiguous, too: not the implemented behaviour (which is fine) is hairy, instead I qualify the edge case itself as such. And it shows - again - how well kept and thought out/through perl is. p5p are doing an awesome job.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'