in reply to Re^6: Using lazy list with a for loop
in thread Using lazy list with a for loop

I agree there are some edge cases to consider depending on the use-case... and I don't know the OPs use cases good enough.

But because of cleaner scope and loop-control statements I'd rather prefer

for (my $iter = get_iter(); my ( $widget ) = $iter->(); ) { ... }

over

my $iter = get_iter(); while ( my ( $widget ) = $iter->() ) { ... }

This approach will put $iter in a tight scope and properly destroy.

Needless to say, if Perl had macros like Lisp, we wouldn't need to repeat that discussion again and again...

Keyword-simple could solve this, but is restricted to statements only.

see also

Can I check if a loop's scope is entered for the first time?

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^8: Using lazy list with a for loop
by ikegami (Patriarch) on Jan 03, 2023 at 16:26 UTC

    I agree there are some edge cases to consider depending on the use-case...

    Code that fails subtly when an exceptions or next/last is occurs? It's not a question of if it's going to bite you, but when.