in reply to Re^2: Getting for() to accept a tied array in one statement
in thread Getting for() to accept a tied array in one statement
This:
for (tie @ary, "My::Class", "some", "contents";) { ... }
is exactly what you should NOT be doing
Read: Tying-Arrays: If someone outside the class tries to dereference the object returned (doubtless thinking it an ARRAY ref), they'll blow up. This just goes to show you that you should respect an object's privacy.
FETCH and FETCHSIZE are exactly for that you can: 'respect an object's privacy':
Something like this:
my $aryt = tie @ary, "My::Class", "some", "contents"; @ary = ... ; for (0..($aryt->FETCHSIZE-1)) { do-something($aryt->FETCH($_)); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Getting for() to accept a tied array in one statement
by hdb (Monsignor) on Apr 16, 2019 at 13:55 UTC | |
by Veltro (Hermit) on Apr 16, 2019 at 14:09 UTC | |
by hdb (Monsignor) on Apr 16, 2019 at 14:12 UTC | |
by Veltro (Hermit) on Apr 16, 2019 at 14:24 UTC | |
by hdb (Monsignor) on Apr 16, 2019 at 14:29 UTC | |
| |
by haukex (Archbishop) on Apr 18, 2019 at 20:22 UTC | |
|