Forum archive 2000-2006

Barbra Bannon - atoi functionality???

Barbra Bannon - atoi functionality???

by Arnold Pizer -
Number of replies: 0
inactiveTopicatoi functionality??? topic started 2/21/2002; 7:46:15 PM
last post 2/27/2002; 8:10:27 PM
userBarbra Bannon - atoi functionality???  blueArrow
2/21/2002; 7:46:15 PM (reads: 2082, responses: 2)
Hello there,

I was wondering if there was a built in function for atoi in WebWork?

-Barbra Bannon

<| Post or View Comments |>


userArnold K. Pizer - Re: atoi functionality???  blueArrow
2/26/2002; 4:47:01 PM (reads: 2311, responses: 0)
Hi,

Do you mean the C command which converts strings to integers? There is no special WeBWorK or Perl command for this, but Perl pretty much does this automatically. E.g. if $a = '23' (i.e. a string), then $a+2 will be the integer 25.

<| Post or View Comments |>


userMichael Gage - Re: atoi functionality???  blueArrow
2/27/2002; 8:10:27 PM (reads: 2291, responses: 0)
For converting one character: one can use
$num = ord($char);
$char = chr($num);



one can also use the "pack" command



@ascii_character_numbers = unpack("C*", "sample");
print "@ascii_character_numbers\n";
115 97 109 112 108 101



See page 9-10 of "Perl Cookbook" by Tom Christiansen & Nathan Torkington (O'Reilly) -- very useful for those who prefer not to reinvent the wheel.

or chr ord pack and unpack in Chapter 3 of Programming with perl

http://www.oreilly.com/catalog/cookbook/

http://www.oreilly.com/catalog/pperl3/

-- Mike

<| Post or View Comments |>