in reply to Internally, how do for() and while() differ?

They are not even close to being equivalent, as evidenced by
my @a = qw( a b c ); for (@a) { print("$_\n"); # Prints "a", then "b", then "c". } while (@a) { print("$_\n"); # Prints an infinite number of blank lines. }

Replies are listed 'Best First'.
Re^2: Internally, how do for() and while() differ?
by GotToBTru (Prior) on Oct 27, 2015 at 16:16 UTC

    The two examples are equivalent in operation, since they have the <> operator around a file handle. In the case of arrays, which the OP did not specify, you are correct. Unless, again, the <> operator is used.

    @a = qw(a b c); for(<@a>) { print "$_\n" }; while(<@a>) { print "$_\n" };

    Both produce the same output, the while loop with considerably more efficiency for large datasets.

    Dum Spiro Spero
      > Unless, again, the <> operator is used.

      Sorry for nitpicking, but IMHO it's not the same "operator" here.

      The OP uses a readline and you are applying a glob.*

      That's one of the more confusing magic features of Perl, so I'm open for further discussion on this matter.

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

      *) similarly are range and flipflop different, even when written with ..

        The way 'for' versus 'while' works seems to be a good case for learning how the magic works, at least a little bit.

        Dum Spiro Spero