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.