in reply to Re: Detecting 'our $foo => 1' mistake? (updated)
in thread Detecting 'our $foo => 1' mistake?

Without being able to test I think the parser sees a list in void context, which is reduced to the last statement.

The => is just a fat comma and the declaration resets the var to undef.

So our $foo => 1; -> undef, 1;

I suppose that at runtime the scalar comma operator will only try to "return" the last statement to void (I know this sounds weird°)

And 0 and 1 are allowed in void (think modules needing a true return value).

That's why the error is only caught for other values.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

°) from Programming Perl

Binary "," is the comma operator. In scalar context it evaluates its left argument in void context, throws that value away, then evaluates its right argument in scalar context and returns that value.

Replies are listed 'Best First'.
Re^3: Detecting 'our $foo => 1' mistake? (scalar comma evaluating to 1)
by haukex (Archbishop) on Jan 21, 2017 at 11:21 UTC

    Hi Rolf,

    Yes, I think you're right:

    $ perl -MO=Deparse,-p -e 'our $foo => 1;' (our($foo), '???');

    Regards,
    -- Hauke D

      Yeah and I checked, it's a pure runtime error.

      I.e. perl -c won't catch.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!