develooper Front page | perl.perl5.porters | Postings from September 2004

Re: [perl #30123] foreach ("", "a".."zzzzzz") confuses range optimizer

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
September 9, 2004 14:47
Subject:
Re: [perl #30123] foreach ("", "a".."zzzzzz") confuses range optimizer
Message ID:
20040909214735.GA1882@iabyn.com
On Tue, Jun 08, 2004 at 08:38:52PM -0000, Michael G Schwern wrote:
> A co-worker exhausted his machine's memory trying to compile this:
> 
> for ( '', 'a'..'zzzzzzz' ) {}
> 
> B::Deparse (using 'zzz') reveals that Perl is trying to build that
> entire list in memory.  The range optimizer seems to only kick in when
> there's nothing but a range in there.
> 
> Our work around is:
> 
> for ( $i = "";  $i ne "aaa";  ($i = $i ? ++$i : "a") ) { print $i }
> 
> Bug/optimizer-miss appears in 5.6.1, 5.8.1 and 5.8.3.

I'm not sure how this can be construed as a bug. In the general
case I'd expect 'a'..'zzzzzzz' to generate a large list, since P5 doesn't
have P6's lazy lists. It just so happens that C<for (X..Y)> is
special-cased, but I don't see why that should lead to a general
expcatation of lazy-listness?

Dave.

-- 
Nothing ventured, nothing lost.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About