in reply to Generating lists from a charset

glob is your friend:
my $charset = '{' . join(',', '0'..'9', 'A'..'Z', 'a'..'z') . '}'; my @charlist = glob( $charset x 3 );
However, that's 238,328 elements. You might want to use glob in a scalar context, such as:
while my $list ( glob( $charset x 3 ) ) { do_something_with($list); }

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: Generating lists from a charset
by BrowserUk (Patriarch) on Dec 23, 2005 at 20:24 UTC
    However, that's 238,328 elements. You might want to use glob in a scalar context

    Unfortunately, using glob in a scalar context does not prevent it from pre-generating the entire list before giving you the first of them, so using it in a scalar context makes little or no difference to either the memory consumed, or the performance.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      You're right. Perhaps it's time for glob to be updated?

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

        I've thought about that, but it is difficult to see how to make it an true iterator without changing the interface to return some kind of 'handle'?

        There is one other existing non-handle, scalar context iterator, each, and that is almost universally eshewed because of it's global nature.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: Generating lists from a charset
by RQZ (Acolyte) on Dec 23, 2005 at 23:09 UTC
    See, I knew I was missing something, thanks :)
    The memory consumed is pretty big though, startup on my machine takes just under 6 seconds :O