#!/usr/bin/perl -w # lex - gene@ology.net use strict; my $str = $ARGV[0] || 'abcde'; my $len = length $str; my $stems = []; for my $i (0 .. $len - 1) { push @{ $stems->[$i] }, substr ($str, $i, $_) for 1 .. $len - $i; } print "'$str':\n"; print "\t@$_\n" for @$stems; print "Breakdown:\n"; my $new = ''; my $num = 0; &successors($stems, $len, 0); exit; sub successors { my ($stems, $len, $i) = @_; for (@{ $stems->[$i] }) { my $n = $i + length; print ' ' x ($i + 1), "$i,$n) $_-\n"; $new .= "$_."; if ($n == $len) { $num++; print "$num) <$new>\n"; $new = ''; } &successors($stems, $len, $n); } }