<?xml version="1.0" encoding="windows-1252"?>
<node id="199684" title="Re: Perl Humor" created="2002-09-20 21:23:11" updated="2005-06-16 08:24:15">
<type id="11">
note</type>
<author id="184322">
gmpassos</author>
<data>
<field name="doctext">
The best is this 3 questinos, making fun with C and ROMAN Numbers:
&lt;p&gt;
------------------------------------------&lt;br&gt;
How do I convert a string to a number?
&lt;p&gt;
Use this atoi function:
&lt;code&gt;
  sub atoi {
    my $t;
    foreach my $d (split(//, shift())) {
      $t = $t * 10 + $d;
    }
  }
  $number = atoi("123");
&lt;/code&gt;
------------------------------------------&lt;br&gt;
How do I convert a number to a string?
&lt;p&gt;
Use sprintf:
&lt;code&gt;
  $string = sprintf("%f", 123.45);
&lt;/code&gt;
&lt;p&gt;
------------------------------------------&lt;br&gt;
How can I tell if a string is a number?
&lt;p&gt;
The simplest method is:
&lt;code&gt;
   if ($string == "$string") { 
   # It is a number
   }
&lt;/code&gt;
Note the use of the == operator to compare the string to its numeric value. However, this approach is dangerous because the $string might contain arbitrary code such as @{&amp;#091;system "rm -rf /"&amp;#093;} which would be executed as a result of the interpolation process. For safety, use this regular expression:
&lt;code&gt;
  if ($var =~ /(?=.)M{0,3}(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})/) {
    print "$var contains a number.\b";
  }
&lt;/code&gt;
&lt;br&gt;
Graciliano M. P.&lt;br&gt;
"The creativity is the expression of the liberty".
&lt;p&gt;
&lt;font size="small"&gt;&lt;strong&gt;Edit&lt;/strong&gt; [kudra], 
2002-09-21 
Fixed literal brackets
&lt;/font&gt;
&lt;/p&gt;</field>
<field name="root_node">
199426</field>
<field name="parent_node">
199426</field>
</data>
</node>
