Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Finding all sets of chars

by blokhead (Monsignor)
on Oct 29, 2005 at 21:21 UTC ( [id://503917]=note: print w/replies, xml ) Need Help??


in reply to Finding all sets of chars

The number of such strings grows exponentially as you increase the desired length (which can out of hand really fast). To prevent from having to keep all of the strings in memory at once, you can use an iterator to give you just one item at a time. Even though the glob function can be used like an iterator, it still internally keeps all of the items in memory at once, so there is no memory gain by using glob to iterate. Here's a simple iterative solution using NestedLoops from Algorithm::Loops:
use Algorithm::Loops 'NestedLoops'; my @chars = ( 'a' .. 'z', 1 .. 9 ); my $len = 3; NestedLoops( [ (\@chars) x $len ], sub { my $str = join "", @_; ## do something with $str } );

blokhead

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found