in reply to bignum and parenthesis

Use

perl -Mbignum -le 'print +( 7 ** 127 ) % ( 524287 )'

See beginning of perlfunc for reason.

Replies are listed 'Best First'.
Re^2: bignum and parenthesis
by NERDVANA (Priest) on Jul 03, 2023 at 18:35 UTC
    Reading the documentation is a good recommendation, but to spell it out quickly, print is a function, not a keyword, and perl functions have optional parentheses around the arguments.
      "Reading the documentation is a good recommendation, but to spell it out quickly, print is a function, not a keyword, and perl functions have optional parentheses around the arguments." then what does the parser think the modulo and number is doing there? from my trial and error it seems it's trying to do modulo using the return value of print function ( = "1" ) , which is a very odd way to interpret such a syntax, since there's no subsequent action to further process that info, store it in a variable, or output to the pipe / to file.
        what does the parser think the modulo and number is doing there?

        It thinks you made a weird coding choice, which is why perl will warn you about it, if you let it:

        C:\> perl -Mbignum -le "use warnings; use strict; print ( 7 ** 127 ) +% ( 524287 )" print (...) interpreted as function at -e line 1. Useless use of modulus (%) in void context at -e line 1. 2125450924568016708443303831058962243331938167363998499854997578694839 +02203328714236393937418376186556719543

        Yet another reason to always use warnings; use strict; or equivalent.

        ... from my trial and error it seems [the parser is] trying to do modulo using the return value of print function ( = "1" ) ...

        Perl can tell you with perfect clarity (update: and lots of parentheses) exactly how it sees the syntax it's trying to compile. See core modules O and B.

        Win8 Strawberry 5.8.9.5 (32) Tue 07/04/2023 15:01:58 C:\@Work\Perl\monks >perl -wMstrict -MO=Deparse,-p -le "print (5+6) + (6*7) + (7**8);" print (...) interpreted as function at -e line 1. Useless use of addition (+) in void context at -e line 1. BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; ((print(11) + 42) + 5764801); -e syntax OK >perl -wMstrict -MO=Deparse,-p -le "print +(5+6) + (6*7) + (7**8); +" BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; print(5764854); -e syntax OK Win8 Strawberry 5.30.3.1 (64) Tue 07/04/2023 15:03:46 C:\@Work\Perl\monks >perl -wMstrict -MO=Deparse,-p -le "print (5+6) + (6*7) + (7**8);" print (...) interpreted as function at -e line 1. Useless use of addition (+) in void context at -e line 1. BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict; ((print(11) + 42) + 5764801); -e syntax OK >perl -wMstrict -MO=Deparse,-p -le "print +(5+6) + (6*7) + (7**8); +" BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict; print(5764854); -e syntax OK


        Give a man a fish:  <%-{-{-{-<

        echo " python3.11.4 :: $( python3 -c 'print( ( 2**3 - 1 )**( 2**7 - 1 + ) % ( 2**19 - 1 ) )' )" echo " perl 5.36 :: $( perl -Mbignum -le 'print ( 2**3 - 1 )**( 2**7 - + 1 ) % ( 2**19 - 1 )' )" echo " gawk 5.2.2 :: $( gawk -p- -Mbe 'BEGIN { print ( ( 2^3 - 1 ) ^ ( + 2^7 - 1 ) ) % ( 2 ^ 19 - 1 ) }' )" python3.11.4 :: 102010 perl 5.36 :: 7 gawk 5.2.2 :: 102010 # gawk profile, created Mon Jul 3 16:24:54 2023 # BEGIN rule(s) BEGIN { 1 print ((2 ^ 3 - 1) ^ (2 ^ 7 - 1)) % (2 ^ 19 - 1) }
        perl is somewhat singular in this regard
Re^2: bignum and parenthesis
by Dallaylaen (Chaplain) on Jul 16, 2023 at 20:15 UTC

    Oh that's why!

    Of course, perl -wle '...' catches it. Yay warnings!