in reply to Opposite of strtol?

A Perl scalar will pretend to be a number or a string as the circumstances require, so you do not need a "string to/from number" function.

Actually, POSIX::strtol does not "parse a string representation of a number in any base into a number" but does a "String to (long) integer translation", which is quite different, but in Perl --IMO-- seldom useful.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: Opposite of strtol?
by ysth (Canon) on Jun 21, 2009 at 19:15 UTC
    A Perl scalar will pretend to be a number or a string as the circumstances require, so you do not need a "string to/from number" function.
    You do if you want a non-base-2/8/10/16 string representation.
    Actually, <c>POSIX::strtol<c> does not "parse a string representation of a number in any base into a number" but does a "String to (long) integer translation", which is quite different, but in Perl --IMO-- seldom useful.
    In principle, yes, but if you know it will work with the range of numbers you have, strtol is possibly fine.