Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Index or iterate - your choice

by thomas895 (Deacon)
on Jan 27, 2021 at 21:12 UTC ( [id://11127538]=note: print w/replies, xml ) Need Help??


in reply to Re: Index or iterate - your choice
in thread Index or iterate - your choice

where there are so many list items or the items are so big, that they would use too much memory to store in an array
Perhaps tie-ing is another good option for this. Then you can get all the semantics of an array for free! (from the user perspective at least)

-Thomas
"Excuse me for butting in, but I'm interrupt-driven..."

Replies are listed 'Best First'.
Re^3: Index or iterate - your choice
by tobyink (Canon) on Jan 27, 2021 at 23:17 UTC

    I did consider including that, but by providing a tied array, you're kind of encouraging end users to treat it as any old array.

    So they might not consider that doing something like:

    foreach my $item ( reverse @array ) { ... }

    Is going to impact performance way more than they might expect.

    If it's exposed as an iterator, then it encourages them to access items in a one-at-a-time sequential fashion. They still can slurp it all into an array, but they can't blame you when that eats up all their memory.

    Not saying it's never a good idea, but situations where it is aren't going to be that common.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-03-28 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found