<?xml version="1.0" encoding="windows-1252"?>
<node id="1018460" title="Re^3: Untillian Headache or about the semantic of until" created="2013-02-12 17:38:49" updated="2013-02-12 17:38:49">
<type id="11">
note</type>
<author id="171588">
BrowserUk</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;Oddly enough, the $wheel &lt; 0 may be unnecessary&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;Indeed.

&lt;p&gt;When I originally posted my suggestion, it was purely on the basis of reading the code snippet in the OP. In general, when doing this kind of iteration with a [while] loop, I check the range of the index before attempting to use it to access the array.

&lt;p&gt;Only after [discipulus] refuted the idea, did I download the snippet and play with it and found that as posted, it "worked okay".

&lt;p&gt;It took a little more investigation to understand that it gets away with it because of perl's propensity to accept negative array indices.

&lt;p&gt;The funny thing is, that in one way, coding it "wrongly" has a benefit:&lt;spoiler&gt;&lt;code&gt;
#! perl -slw
use strict;

sub incOdo {
    my @odo = @_;
    my $wheel = $#odo;

#    until( $wheel &lt; 0 || $odo[ $wheel ] &lt; 9  ) {
    until( $odo[ $wheel ] &lt; 9 || $wheel &lt; 0  ) {
        $odo[ $wheel ] = 0;
        $wheel--;
    }
    if( $wheel &lt; 0 ) {
        return;
    }
    else {
        $odo[ $wheel ]++;
        return @odo;
    }
}

my @odo = (0) x 2;

for( 1 .. 102 ) {
    print join '', @odo = incOdo( @odo );
}

&lt;/code&gt;&lt;/spoiler&gt;

&lt;ul&gt;&lt;li&gt;Coded 'correctly' attempts to iterate beyond the scale of the odometer fail silently:&lt;code&gt;
1
2
3
...
97
98
99




&lt;/code&gt;

&lt;/li&gt;&lt;li&gt;But coded 'wrongly', that beyond range attempt fails noisely:&lt;code&gt;
1
2
3
...
98
99

Use of uninitialized value within @odo in numeric lt (&lt;) at C:\test\junk31.pl line 9.

Use of uninitialized value within @odo in numeric lt (&lt;) at C:\test\junk31.pl line 9.


&lt;/code&gt;
&lt;p&gt;which could be seen as an advantage :)

&lt;p&gt;Of course, there are better ways of detecting the failure...
&lt;/li&gt;&lt;/ul&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-171588"&gt;
&lt;hr /&gt;
&lt;font size=1 &gt;
&lt;div&gt;With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'&lt;/div&gt;
&lt;div&gt;Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.&lt;/div&gt;
&lt;div&gt;"Science is about questioning the status quo. Questioning authority". &lt;/div&gt;
&lt;div&gt;In the absence of evidence, opinion is indistinguishable from prejudice.
&lt;/div&gt;
&lt;/font&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1018143</field>
<field name="parent_node">
1018452</field>
</data>
</node>
