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

Re^3: Fold a list using map splices

by Aristotle (Chancellor)
on Feb 20, 2003 at 17:54 UTC ( #237157=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Fold a list using map splices
in thread Fold a list using map splices

I'm not saying that my approach is the sole possible correct one, but I do believe that yours is wrong. The way it turns out to work is more of an accidental feature than something you should rely on. If you really don't want to create a temporary array, I suggest you do something like
map func1([ splice @_, 0, $num_elements ]), 0 .. (@_/$num_elements);
Iterating the map over an array while modifying it at the same time is wrong.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^4: Fold a list using map splices
by hiseldl (Priest) on Feb 20, 2003 at 21:28 UTC

    Ok. After more experimentation, I understand your point. Basically the question you are asking me is "why should I iterate over the last part of the list that may not exist?"

    So, what I need to do is change the list at the end of the map, to a list that will be used to count the new elements, rather than counting all of the elements in the original list.

    While I still disagree with you about "right" and "wrong," you have made a valuable point which makes the map more efficient. Thank you.

    --
    hiseldl
    What time is it? It's Camel Time!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-06-30 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (97 votes). Check out past polls.

    Notices?