<?xml version="1.0" encoding="windows-1252"?>
<node id="448578" title="Re^2: Example 2: incrementing &quot;something&quot;" created="2005-04-17 00:35:14" updated="2005-07-19 21:58:47">
<type id="11">
note</type>
<author id="448536">
Mabooka-Mabooka</author>
<data>
<field name="doctext">
&lt;h2&gt; Perl allows to use arithmetics on string &lt;/h2&gt;

Here's the code:
&lt;code&gt;
#!/usr/local/bin/perl -w

use strict;


sub step_over_desert # () I won't repeat this mistake anymore!!!
{
    print "Tsock...\n";
}


sub cover_the_distance # () I won't repeat this mistake anymore!!!
{
    my ($me, $desert_width, $max_spit_distance, $num_legs, $last_name, $day_phone, $days_without_water) = @_;

    my $num_steps=0;
    while($desert_width)
   {
       my $todo = $desert_width * $num_legs;
       print "$desert_width miles remaining; $todo steps yet to do.\n";

       step_over_desert();
       $desert_width--;

       $num_steps += $num_legs;
   }

    print "Steps made: $num_steps\n";
}


#cover_the_distance("strong animal", 5, 15, 4, "Mabooka", "(123)-456-7890", -1);
cover_the_distance("strong animal", "five thousand miles", 15, 4, "Mabooka", "(123)-456-7890", -1);


1;

&lt;/code&gt;

&lt;h3&gt; Don't try it at home&lt;/h3&gt;

Well, I recommend at the very least to redirect the output to a file:-).

&lt;h3&gt; Why people do this?&lt;/h3&gt;

Again, the main reason: because it allows you. One may expect either a compile-time error or a run-time exception. But Perl allows you to shoot your own foot.

&lt;br&gt;Actually, this is an obfuscated (starting to love the word) code from a real-life app. The real application would send a query over the wire to the server, &lt;br&gt;get a responce line --

&lt;br&gt;-- that should look smth. like this: &lt;br&gt;
200 OK 578
&lt;br&gt;-- meaning " there're 578 lines yet to read from the socket,

&lt;br&gt; parse this line and create a loop:
&lt;code&gt;
while($numlines) {
   get_next_one(...);
   $numlines--;
   ...
}
&lt;/code&gt;

Well guess what? Once in 10000 times the server would get tired and send a garbled status line -- smth. like:&lt;br&gt;
&lt;code&gt;
200 OK whatever,man
&lt;/code&gt;

and 
&lt;code&gt;
  (while "whatever,man"--)
     {....}
&lt;/code&gt;

will start the almost infinite loop. (Try the code above).
&lt;br&gt;

&lt;h3&gt;Solution&lt;/h3&gt;

Be aware.
&lt;br&gt;use int($n).
&lt;br&gt;Ask your new hires during the inteview: "What is the result of the following operation:
&lt;code&gt;
"Larry"--;
&lt;/code&gt;
-?.
&lt;br&gt;</field>
<field name="root_node">
46769</field>
<field name="parent_node">
448568</field>
</data>
</node>
