NAME

String::Substrings - module to extract some/all substrings from a string

SYNOPSIS

 use String::Substrings;

 my @parts = substrings $string;
 

DESCRIPTION

This module has only one method substrings. It is called as

substrings STRING

It returns all substrings with a length of 1 or greater including the string itselfs. The substrings returned are sorted for the length (starting with length 1) and for their index. E.g. substrings "abc" returns ("a","b","c","ab","bc","abc"). This order is guaranteed to stay even in future versions. That also includes that the returned list of substrings needn't be unique. E.g. substrings "aaa" returns ("a","a","a","aa","aa","aaa").

substrings "" returns an empty list, substrings undef returns undef and every call with a hash/array-reference let substrings die.

In scalar context it returns the number of substrings found, allthough I can't imagine that it is useful. (It's simple to calculate without determining all the substrings: length($string) * (length($string)+1) / 2. Especially the scalar context behavior could be changed in future versions.

Please take care to the length of the strings passed. The number of substrings grows with the square of the string's length. I only tested it till a string length of 100.

EXPORT

substrings

SEE ALSO

Algorithm::ChooseSubsets

AUTHOR

Janek Schleicher, <bigj@kamelfreund.de>

COPYRIGHT AND LICENSE

Copyright 2002 by Janek Schleicher

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.