#!/usr/bin/env perl
#-*-Perl-*-
use v5.16;
my @a = qw<a b c>;
my $b = [@a];
while (my ($i, $v) = each $b) {
say "$i: $v";
}
while (my ($i, $v) = each [@a]) {
say "$i: $v";
}
Trying out the arrayref functionality introduced in 5.14.
The first loop executes the expected 3 times, printing the expected values.
The second loops infinitely, always giving 0 for $i and 'a' for $v.
Hashrefs display the same behavior.
my $b = {map { $_ => $_ } qw<a b c>};
while (my ($i, $v) = each $b) {
say "$i: $v";
}
while (my ($i, $v) = each {map { $_ => $_ } qw<a b c>}) {
say "$i: $v";
}