<?xml version="1.0" encoding="windows-1252"?>
<node id="771481" title="Re: $#array issue" created="2009-06-14 19:01:43" updated="2009-06-14 19:01:43">
<type id="11">
note</type>
<author id="615480">
citromatik</author>
<data>
<field name="doctext">
&lt;p&gt;If you comment the second line, &lt;c&gt;$end&lt;/c&gt; will be undefined in the loop condition. Please, &lt;c&gt;use strict&lt;/c&gt; and &lt;c&gt;use warnings&lt;/c&gt; in your code if you want to learn Perl the easy way. This code works as expected:&lt;/p&gt;

&lt;c&gt;
use strict;
use warnings;

my @array=(1,2,3,4,5,6,7,8,9);
my $end=($#array+1);
my $index = 0;
while($index &lt; $end){
    my $last=pop(@array);
    print "$last\n";
    $index++;
}

&lt;/c&gt;

&lt;p&gt;BTW, here are another ways to address the same problem:&lt;/p&gt;
&lt;c&gt;

my @array = (1..9);
print +(pop @array),"\n" while (@array);
&lt;/c&gt;
&lt;p&gt;
or even
&lt;/p&gt;

&lt;c&gt;
my @array = (1..9);
print "array[$_]\n" for (reverse (0..$#array));
&lt;/c&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-615480"&gt;
&lt;p&gt;&lt;i&gt;citromatik&lt;/i&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
771479</field>
<field name="parent_node">
771479</field>
</data>
</node>
