You are modifying @arr inside the loop in such a way that $thing containing 'a' at each iteration. It's easier to see with some modifications:

use warnings; use strict; use diagnostics; my @arr = ('a'..'z'); print "@arr\n"; foreach my $thing (@arr) { print "[$thing]"; my $ele = pop @arr; my $stuff = unshift @arr, $ele; print "$ele - @arr\n"; } __END__ a b c d e f g h i j k l m n o p q r s t u v w x y z [a]z - z a b c d e f g h i j k l m n o p q r s t u v w x y [a]y - y z a b c d e f g h i j k l m n o p q r s t u v w x [a]x - x y z a b c d e f g h i j k l m n o p q r s t u v w [a]w - w x y z a b c d e f g h i j k l m n o p q r s t u v [a]v - v w x y z a b c d e f g h i j k l m n o p q r s t u [a]u - u v w x y z a b c d e f g h i j k l m n o p q r s t [a]t - t u v w x y z a b c d e f g h i j k l m n o p q r s [a]s - s t u v w x y z a b c d e f g h i j k l m n o p q r [a]r - r s t u v w x y z a b c d e f g h i j k l m n o p q [a]q - q r s t u v w x y z a b c d e f g h i j k l m n o p [a]p - p q r s t u v w x y z a b c d e f g h i j k l m n o [a]o - o p q r s t u v w x y z a b c d e f g h i j k l m n [a]n - n o p q r s t u v w x y z a b c d e f g h i j k l m [a]m - m n o p q r s t u v w x y z a b c d e f g h i j k l [a]l - l m n o p q r s t u v w x y z a b c d e f g h i j k [a]k - k l m n o p q r s t u v w x y z a b c d e f g h i j [a]j - j k l m n o p q r s t u v w x y z a b c d e f g h i [a]i - i j k l m n o p q r s t u v w x y z a b c d e f g h [a]h - h i j k l m n o p q r s t u v w x y z a b c d e f g [a]g - g h i j k l m n o p q r s t u v w x y z a b c d e f [a]f - f g h i j k l m n o p q r s t u v w x y z a b c d e [a]e - e f g h i j k l m n o p q r s t u v w x y z a b c d [a]d - d e f g h i j k l m n o p q r s t u v w x y z a b c [a]c - c d e f g h i j k l m n o p q r s t u v w x y z a b [a]b - b c d e f g h i j k l m n o p q r s t u v w x y z a [a]a - a b c d e f g h i j k l m n o p q r s t u v w x y z

Before the loop @arr contains 'a'..'z' as expected.

First iteration: $thing ($arr[0]) contains 'a', $ele ($arr[25]) contains 'z' which goes to the beginning and now 'a' is at $arr[1].

Second iteration: $thing ($arr[1]) contains 'a', $ele ($arr[25]) contains 'y' which goes to the beginning and now 'a' is at $arr[2].

Wash, rinse, repeat until you've reached $arr[25].

update: removed meaningless comment


In reply to Re: Array confusion. by Mr. Muskrat
in thread Array confusion. by anonypl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.