Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Is there a way more easy? (NestedLoops)

by tye (Cardinal)
on Jun 24, 2012 at 18:21 UTC ( #978071=note: print w/ replies, xml ) Need Help??


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        


Comment on Re^2: Is there a way more easy? (NestedLoops)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2013-06-20 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How many continents have you visited?









    Results (678 votes), past polls