strtol#

Parse a signed integer from the start of a string, in a given base.

תקציר#

use POSIX qw(strtol);
my ($n, $unparsed) = strtol("0x2a rest", 0);   # (42, 5)

מה מוחזר#

A two-element list: the parsed integer and the number of bytes that were not consumed. Base 0 auto-detects from prefix (0x, 0b, leading 0); otherwise $base must be 2-36.

מקרי קצה#

  • Invalid base: returns (undef, undef) and sets $! to EINVAL.

  • Overflow: returns LONG_MIN / LONG_MAX and sets $! to ERANGE.

הבדלים מן ה-upstream#

Fully compatible with upstream POSIX.

ראו גם#

  • strtoul - unsigned variant.

  • strtod - floating-point variant.