in reply to Generating lists of strings

use strict; use warnings; use Math::NumberBase; my $length = 4; my $b = Math::NumberBase->new($length); my $start = $b->to_decimal("1" x $length); my $end = $b->to_decimal("${\($length-1)}" x $length); print $b->from_decimal($_), "\n" for $start .. $end; __END__ 1111 1112 1113 1120 1121 1122 1123 1130 1131 1132 1133 1200 1201 ... 3310 3311 3312 3313 3320 3321 3322 3323 3330 3331 3332 3333

Replies are listed 'Best First'.
Re^2: Generating lists of strings
by Anonymous Monk on Jan 24, 2010 at 15:47 UTC
    And in the spirit of jethro's analysis, here's a simpler method:
    my $length = 4; my $b = Math::NumberBase->new($length-1); my $start = 0; my $end = $b->to_decimal("${\($length-2)}" x $length); print "$_\n" for map {join'', map {$_+1} split(//,$b->from_decimal($_))} $start .. $end;
Re^2: Generating lists of strings
by Anonymous Monk on Jan 24, 2010 at 15:37 UTC
    Sorry, I missed that you have no ending zeros. This change recreates the desired output:
    print $b->from_decimal($_), "\n" for grep { $_ % $length } $start .. $end;