in reply to Iterating through string combinations

my $num = "000"; { $num =~ s{(^|.)(z*)$}{ my ($left, $right) = ($1, $2); $left =~ tr/0-9a-y/1-9a-z/ or $left = "10"; $right =~ tr/z/0/; $left . $right; }e; print "$num\n"; redo while length $num < 20; }
Be prepared to loop for a very long time.

-- Randal L. Schwartz, Perl hacker


update: Yes, delete the ^| up there.

Replies are listed 'Best First'.
Re: Re: Iterating through string combinations
by I0 (Priest) on Dec 18, 2001 at 08:47 UTC
    I think you mean either
    $num =~ s{(.)(z*)$}{
    or
    $left =~ tr/0-9a-y/1-9a-z/ or $left = "1";
      Ahh, no the problem is that I had (.|^) and tested it, but then decided (incorrectly) it should be (^|.). I like your (.) solution the best.

      -- Randal L. Schwartz, Perl hacker