But you can work around this passing a reference to the final array:
use strict;
use warnings;
print join "\n", comb_thormod('A'..'R');
sub comb_thormod {
my $c_out = [];
permute_thormod( '', $_, $c_out, @_ ) for ( 0 .. $#_ );
return @$c_out;
}
sub permute_thormod {
my ( $str, $depth, $c_out, @chars ) = @_;
if ( !$depth-- ) {
foreach (@chars) {
push @$c_out, $str . $_;
}
}
else {
permute_thormod( $str . $chars[$_], $depth, $c_out,
@chars[ ( $_ + 1 ) .. ($#chars) ] )
for ( 0 .. $#chars );
}
}
even if results show your solution is still slightly more efficient (-2% / 5% scissor).
OTOH, I'd still prefer the version without the static variable - should work in a multithreaded environment, at least :)
Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')
Don't fool yourself.
|