Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: file processing, while and foreach: a n00b experience

by Juerd (Abbot)
on Aug 27, 2003 at 09:08 UTC ( [id://286985]=note: print w/replies, xml ) Need Help??


in reply to file processing, while and foreach: a n00b experience

It helps to know that

while (<FH>) {
is equivalent to
while (defined($_ = readline *FH)) {
and that foreach (LIST) flattens the list it gets. (Well, there are some special cases like foreach (ARRAY) and foreach (RANGE) that are more efficient.)

See the documentation on readline to find out how it behaves differently when used in list context.

In Perl 6, this will not be much of a problem, since it will have "lazy lists". A normal for (LIST) will do what you mean, in an efficient way.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re^2: file processing, while and foreach: a n00b experience
by Aristotle (Chancellor) on Aug 28, 2003 at 12:12 UTC
    In fact I suspect that, true to the Perl optimization rule of not involving the dispatcher if at all possible, using for in Perl 6 to implictly alias to the topic and letting the lazy behaviour implicitly determine EOFness for you will be more efficient than using while while explicitly assigning to a variable and explicitly testing for definedness. </handwaving>

    Makeshifts last the longest.

Re: Re: file processing, while and foreach: a n00b experience
by John M. Dlugosz (Monsignor) on Sep 02, 2003 at 20:39 UTC
    Hopefully, that will be a lazy list automatically in Perl 6 without having to do anything special or even worrying about it fitting in memory (or the file being finite/completed).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://286985]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-16 19:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found