Um, cool! But it leaks memory at an insane rate on 5.6.1.Jeff Pinyan explained this one to me. The code in the regex captures the first instance of @ss, and keeps appending to it, 1023 new elements every time through the loop. You can fix the problem by using a static variable:
{ my @ss; sub substrings { @ss = (); $_[0] =~ /.*?(.+?)(?{push @ss, $1})(?!)/; @ss; } }
--
Mark Dominus
Perl Paraphernalia
In reply to Re: Finding all substrings
by Dominus
in thread Finding all substrings
by TheHobbit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |