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

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

Thread Previous | Thread Next
From:
wolfsage
Date:
November 24, 2012 08:15
Subject:
Re: [perl #30123] foreach ("", "a".."zzzzzz") confuses range optimizer
Message ID:
CAJ0K8bj0YAAuZLFaect-6JYpOfsC-9ADPSQB0fRZ0Hy8wv1ULQ@mail.gmail.com
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?

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)

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