in reply to whats wrong with this code?

While I prefer Marshall's solution, TIMTOWTDI

for completeness two other approaches:

use strict; use warnings; my @array= 1..10; do { print "@array\n" } while defined shift @array; @array= 1..10; for (1..@array) { print "@array\n"; shift @array; }

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: whats wrong with this code?
by afoken (Chancellor) on Jan 18, 2017 at 13:06 UTC
    my @array= 1..10; do { print "@array\n" } while defined shift @array;

    That does not work if @array may contain undef.

    >perl -Mstrict -w -M-warnings=uninitialized -E 'my @a=(1..5,undef,6..1 +0); say "@a" while defined shift @a' 2 3 4 5 6 7 8 9 10 3 4 5 6 7 8 9 10 4 5 6 7 8 9 10 5 6 7 8 9 10 6 7 8 9 10 >

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)