in reply to Re: use constant moudle
in thread use constant module

"Normally this gets a warning, but you've run into a case where it doesn't"

Update: You only get the warning if you ask for it and put exactly one space between the print and the left parenthesis. Using zero or more than one space, and no warning is emitted.

$ perl -we 'use constant WD => qw{Sun Mon}; print(WD)[1]' syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors. $ perl -we 'use constant WD => qw{Sun Mon}; print (WD)[1]' print (...) interpreted as function at -e line 1. syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors. $ perl -we 'use constant WD => qw{Sun Mon}; print (WD)[1]' syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors. $ perl -we 'use constant WD => qw{Sun Mon}; print (WD)[1]' syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors.

I tried up to five spaces: same result. Very weird!

Original text:

If you don't ask for warnings, you don't get warnings:

$ perl -e 'use constant WD => qw{Sun Mon}; print (WD)[1]' syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors.

If you ask for warnings, you get warnings:

$ perl -we 'use constant WD => qw{Sun Mon}; print (WD)[1]' print (...) interpreted as function at -e line 1. syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors.

There's nothing special something very strange about this case.

— Ken

Replies are listed 'Best First'.
Re^3: use constant module (was moudle)
by Anonymous Monk on Feb 24, 2016 at 11:51 UTC

    Sorry but you're wrong, look closely:

    $ perl -we 'use constant WD => qw{Sun Mon}; print (WD)[1]' print (...) interpreted as function at -e line 1. syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors. $ perl -we 'use constant WD => qw{Sun Mon}; print (WD)[1]' syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors.

      That's very strange and unexpected behaviour. I've investigated this further and updated my post with the results.

      — Ken