in reply to Re: Getting for() to accept a tied array in one statement
in thread Getting for() to accept a tied array in one statement
for (tie @ary, "My::Class", "some", "contents") { ... } # NOPE
does not work because for() gets a single-element list which is the tied object, not the tied array itself.
for (do { tie @ary, "My::Class", "some", "contents"; @ary }) { ... } #NOPEdoes not work because for() gets an ordinary (non-magical) list of values. All the values from the tied array have been FETCH-ed. I need to iterate over the tied array so code inside the loop block and FETCH are executed once for each element, together.
tie @ary, "My::Class", "some", "contents"; for (@ary) { ... }
works, but I want something more similar to:
for (wrapper(@ary)) { ... }
where @ary is an ordinary array or a list of values.
|
|---|