Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^11: Getting for() to accept a tied array in one statement

by ikegami (Patriarch)
on Apr 20, 2019 at 12:32 UTC ( [id://1232832]=note: print w/replies, xml ) Need Help??


in reply to Re^10: Getting for() to accept a tied array in one statement
in thread Getting for() to accept a tied array in one statement

The sole purpose of an Iterator should be traversing (up, down) through the elements of the collection.

But that's what the OP wants, assuming the code the OP wants to execute for each element specifically fetches or generates the element to be returned.

If that's not what the OP wants, there's no point to their wrapper, so there's no point to a tied array or iterator. They should simply place the logic in the loop itself.

The rest of your post makes no sense. You only need three implementations with an iterator if you have three implementations with a tied array since the tied array approach is literally being used as an iterator (a role it is badly equipped to handle). The tied array is pure needles complexity and overhead, the very thing programmers should be avoiding. It adds absolutely no value.

Tied arrays are a hack that should only be used to shoehorn logic into existing bad code. The very idea of a tied variable (to make code look like variable) is a bad practice. They should be used as a last resort. They should definitely be avoided when they are costly and don't provide any benefits like in this case.

  • Comment on Re^11: Getting for() to accept a tied array in one statement

Log In?
Username:
Password:

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

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

    No recent polls found