in reply to whats wrong with this code?

As side note nor your expectation nor your output can be as you posted: you shift before printing, so first number will always be 2.

The interesting thing is that this to avoid syntax always stops after the first middle of the array:

perl -E "@ar=(1..$ARGV[0]);foreach(@ar){shift @ar;}print qq(@ar\n)" 4 3 4 perl -E "@ar=(1..$ARGV[0]);foreach(@ar){shift @ar;}print qq(@ar\n)" 10 6 7 8 9 10 perl -E "@ar=(1..$ARGV[0]);foreach(@ar){shift @ar;}print qq(@ar\n)" 20 11 12 13 14 15 16 17 18 19 20

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: whats wrong with this code?
by purnak (Acolyte) on Jan 18, 2017 at 11:10 UTC
    Thanks for the answer. But

     so first number will always be 2

    Why is that so? Shift destroys the array for good. Isnt it?
      Sorry perhaps i've not noticed your first print "@array\n"; statement (or you have added it? ;=)

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.