Hello William,
I have perused HOP, but I find that, besides the gooi idea of wrapping
the sub in an Iterator, it did not really answer what I wanted, so I
wrote my own, and I am polishing my own.
The idea is as following: generating Strings (aka "Permutations with
Repetition) can be done using really the same algorithm as counting, so
we just map those indices to the charset we want to use. Unfortunately,
my incidental perl gets rusty as I use it every six months, while my
taste for nice style and appropriate doses of syntactic sugar does not
(no doubt Damian's fault).
please check out my comments below...
----------------------------------------------------------------------------
#! /usr/bin/perl
use strict;
#charset to compose the strings (permutations) with
my @charset = qw(a b c d);
#length of strings to be generated
my $maxlen = 4;
my @indices = (0, 0, 0, 0); # how do I init this array so that it is
$maxlen zeros long ?
my $final = $#charset x 4;
until((join "", @indices) eq $final) #last case "dddd" is missing! must
really specialcase it ?
{
print join("", @[EMAIL PROTECTED])."\n"; #more stylish concatenation ?
for my $i (@indices)
{
unless (++$i == $maxlen) #use the default ($_, etc) variables ?
{ last; } # can we get rid of some braces somehow ?!
$i = 0;
}
}
-----------------------------------------------------
best -f
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm