I know this thread is pretty old, but I just read it and saw a way to improve the code. One thing you could do that should speed things up is to store the results in a hash. You can then avoid using
uniq and you will only be doing the matching operation on pieces you haven't yet seen.
#!/usr/bin/perl -w
use strict;
my $line;
my %count;
while ( defined ( $line = <> ) ) {
chomp $line;
for my $a ( 1 .. length ( $line ) ) {
for my $b ( 1 .. ( length ( $line ) + 1 - $a ) ) {
my $out = substr ( $line, $a - 1, $b );
next unless $count{ $out }; # so you don't have to use uniq
next if ( $count{ $out } = () = $line =~ /$out/g ) > 1;
print "length: $b digits: $out quantity: $count{ $out }";
}
}
}
I just glanced through the other comments and saw some good points in there too, so if you're using this code make sure to take those into account as well. I didn't want to rewrite the whole thing, but just wanted to point out how the hash could be useful.