in reply to Unconventional exit from while loop

Generally I'm trying to avoid to call iterators in scalar context, because of edge cases where a useful return value is false and stops the while loop.

I prefer clear stop values...

For instance

while( my ( $z, $y, $x, $w ) = @{ $iter->next // last } ) { }

is terminated for

  1.  return (); i.e.  return;
  2.  return undef;
  3.  return [];

but

while( my ($a_permutation) = $iter->next ) { ... }

is only terminated in the first case. You still have the liberty to return undef or [] as valid values.

In your special snippet undef or [] don't make much sense, but this approach helps avoiding quirks like 0 but true !

Anyway I wonder why the iterator was designed to return an array reference...

Why not right away returning a list?

while( my @permutation = $iter->next ) { ... }

Cheers Rolf

( addicted to the Perl Programming Language)