All pastes #897452 Raw Edit

Something

public text v1 · immutable
·published 2008-02-09 15:58 UTC
rendered paste body
I have written the following code to create a simple linked list, and walk through it, printing each element ...

Why does it only print up to 81 instead of the expected 100?

<code>
<pre>
use strict;

my $list = undef;

for (reverse 0..10){
        $list = [$list, $_ * $_];
}


sub walk_list {
        my $head = shift;
        my $steps = shift;
        my $action = shift;

        while ( $steps && $head->[0] ){
                $action->($head);
                $head = $head->[0];
                $steps--;
        }
}

my $print_list = sub {my $node = pop; print $node->[1], "\n";};

walk_list($list, 10, $print_list);

</code>