Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Fold a list using map splices

by Aristotle (Chancellor)
on Feb 20, 2003 at 17:54 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-25 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found