in reply to Generating lists of strings
#! perl -slw use strict; sub nFor(&@) { my $code = shift; die "First argument must be a code ref" unless ref( $code ) eq 'CO +DE'; my @limits = @_; my @indices = ( 0 ) x @limits; for( my $i = $#limits; $i >= 0; ) { $i = $#limits; $code->( @indices ), ++$indices[ $i ] while $indices[ $i ] < $limits[ $i ]; $i = $#limits; $indices[ $i ] = 0, ++$indices[ --$i ] while $i >= 0 and $indices[ $i ] == $limits[ $i ]; } } my @digits = 1 .. 3; nFor { print join '', @digits[ @_ ]; } ( 3 ) x 4;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generating lists of strings
by ikegami (Patriarch) on Jan 24, 2010 at 19:18 UTC | |
by BrowserUk (Patriarch) on Jan 24, 2010 at 19:51 UTC | |
by ikegami (Patriarch) on Jan 24, 2010 at 21:53 UTC | |
by BrowserUk (Patriarch) on Jan 24, 2010 at 22:38 UTC | |
by ikegami (Patriarch) on Jan 24, 2010 at 22:48 UTC | |
| |
by BrowserUk (Patriarch) on Jan 25, 2010 at 01:16 UTC | |
by BrowserUk (Patriarch) on Jan 25, 2010 at 00:56 UTC | |
by ikegami (Patriarch) on Jan 25, 2010 at 02:54 UTC | |
|