XP is just a number | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
the scalar itself is fetched only once Is that guarenteed? If it is I almost withdraw my opinion. I say almost, because I still think it's unnecessary complicated (in that it uses a global as loop variable). If you change to the not completely unusual construct for whatever reason it'll demonstrate why I think this is playing with fire -- you have an extra thing to keep in mind two years later when you patch the code. As you say yourself The important point is that the contents of the array it points to at start doesn't changeThese's a general concensus that using globals like this is A Bad Thing, even if it's not such an obvious case. Not only do you have to remember that directly inside the loop not change @$chain, but you can't get the idea to assign to @$chain in &__Set_MethodChain__. That's a lot of unnecessary conditions just to not copy a presumably small array. If you copy the array you don't have anything extra to worry about and that might save yourself from future troubles. Indeed, the code works, I just get a bad feeling when I see it. :-) if you want to build a chain of methods without the length of it known in advance, then the sub solution can be more difficult You can easily compose new chains using other "sub chains", if that's what you're talking about. Maybe I misunderstood? ihb
See perltoc if you don't know which perldoc to read! In reply to Re^3: Method chain object with easy syntax
by ihb
|
|