in reply to Print Statement

1225.5, 1225.50, 12255E-1 and 1_225.5 are all stored indentically internally, and print will print them all as 1225.5 because that is how print displays the value 1225.5. print has no idea how the number came to be; it just knows its value. If you wish to preserve the underscores, you want to treat the number as a string instead of as a number, so put quotes around it.

Replies are listed 'Best First'.
Re^2: Print Statement
by Anonymous Monk on Feb 21, 2011 at 10:57 UTC
    I was trying to do :
    perl -e 'print 0100101."\n"'
    As expected I got the decimal equivalent of octal as:
    32833
    However, doing
    perl -e 'print 100101."\n"'
    returned
    String found where operator expected at -e line 1, near "100101."\n"" (Missing operator before "\n"?) syntax error at -e line 1, near "100101."\n"" Execution of -e aborted due to compilation errors.
    Any idea why this fuss about a zero? Not a burning problem or something. Just curious.

      The "." is part of the number.

      print 100101. "\n" ^ missing operator

      Add a space before the ".".