in reply to Re: Is there a way more easy?
in thread Is there a way more easy?
Yeah, that's one advantage of the implementation of this type of iterator that is provided in Algorithm::Loops:
use Algorithm::Loops qw< NestedLoops >; my $listIter = NestedLoops( [ ( ['a'..'z','A'..'Z','_'] ) x 6 ], { OnlyWhen => 1 }, # { OnlyWhen => sub { 3 <= @_ } }, ); my $strIter = sub { join '', $listIter->(); }; my $str; while( $str= $strIter->() ) { print $str, $/; }
The OnlyWhen option lets you get all lengths or just pick which lengths you are interested in.
(I should add an option for wrapping the return value so I could build the string iterator without the extra step.)
- tye
|
|---|