Quote:

> > Okay, this is bugging the hell out of me, and it really shouldn't be that

> > hard. Problem is, neither of the books I have tells me how to do it...

> > I'm reading a number from a file. Only thing in the file is that number.

> > No problem. Except when I use 'chop' to read it, it becomes a string. I

> > want to now manipulate this as a number. How? The command must exist -

> > hell, even AppleBASIC had the val()_ command.

> > So, how do I convert a number to a string and vice versa?

Perl does it for you automatically depending on the context. For instance:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

$num = "58"; # A string...

$other_num = $num + 67; # turns into a number in a numeric context

$third_num = $num + 5.67;

print ("Numbers: $num, $other_num, $third_num\n");

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And the output is....

Numbers: 58, 125, 63.67

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is one of the cool features of Perl - I used it to solve a math

problem once, which was this: find all triples of three digit numbers such

that the sum

of the first two numbers equals the third number, AND each of the digits

1..9 only appear once in the three numbers.

Examples: 783 729

+162 +135

--- ---

945 864

Using Perl's easy transition from integers to strings made the program

that solved this problem pretty easy.

The other cool part of this problem (in case anyone's interested in this

kind of thing around here): what can you say about the sum of the digits

in the answer? For instance, 9+4+5 = 18, and 8+6+4 = 18.

-Ken Williams