in reply to Re: Re: Finding all substrings
in thread Finding all substrings
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Finding all substrings
by samtregar (Abbot) on Apr 24, 2002 at 21:28 UTC |