In the second case, print is being interpreted as a function, i.e. print(WEEKDAYS)[1];, where the [1] doesn't work. Normally this gets a warning, but you've run into a case where it doesn't:
$ perl -we 'print (3+4),5;' print (...) interpreted as function at -e line 1. Useless use of a constant (5) in void context at -e line 1. 7 $ perl -we 'print (WEEKDAYS)[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 'print (WEEKDAYS)[1];' syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors.
Two workarounds in addition to your "case #1":
$ perl -we 'print +(3+4),5;' # disambiguate 75 $ perl -we 'print((3+4),5);' # explicit parens 75
Tip: B::Deparse comes in handy for debugging here:
$ perl -MO=Deparse,-p -e 'print (3+4),5;' (print(7), '???');
In reply to Re: use constant moudle
by Anonymous Monk
in thread use constant module
by Hosen1989
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |