develooper Front page | perl.perl5.porters | Postings from November 2012

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

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
November 24, 2012 12:57
Subject:
[perl #30123] foreach ("", "a".."zzzzzz") confuses range optimizer
Message ID:
rt-3.6.HEAD-24979-1353790633-1215.30123-15-0@perl.org
On Sat Nov 24 08:16:13 2012, alh wrote:
> On Sat, Nov 24, 2012 at 10:34 AM, Father Chrysostomos via RT <
> perlbug-followup@perl.org> wrote:
> 
> > >
> > > Is there any other case besides for/foreach that 'a..z' should
> iterate on
> > > the fly rather than immediately generate a list in memory?
> >
> > I hadn’t thought of that, but if it could iterate on the fly in more
> > places it would allow for more idiomatic code.
> >
> >
> I see these as being sensible uses of iteration:
> 
> for ('a'..'z', qw(cat dog mouse), 1..10) { print $_ }
> 
> my @found = grep { $_ =~ /./ } 1..10;
> 
> my %hash = map { $_ => 1 } 1..10*;*
> 
> But should this iterate at runtime or be pregenerated as it is now?

That’s a hard question. :-)

> 
> my @arr = (1..10);
> 
> If it's in a sub that's never hit, there's a memory saving there if it
> iterates when requested.
> 
> -- Matthew Horsfall (alh)


-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=30123

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