in reply to iterators: traversing arbitrary data structure
Update: OOPS! The solution in this post will show you all the values, but will not allow you to change them. See my reply to this post for a more appropriate solution.
Well, you could do
if you defined get_value_iter as follows:my $iter = get_value_iter($oWkBook); while ($iter->(my $item)) { print("$item\n"); }
sub get_value_iter { my @values = @_; my $sub_iter; return sub { our $rv; local *rv = \$_[0]; for (;;) { if ($sub_iter) { if ($sub_iter->($rv)) { return 1; } undef $sub_iter; } return if not @values; $rv = shift(@values); while (ref($rv) eq 'SCALAR') { $rv = $$rv; } if (ref($rv) eq 'ARRAY') { $sub_iter = get_value_iter(@$rv); next; } if (ref($rv) eq 'HASH') { $sub_iter = get_value_iter(values %$rv); next; } return 1; } }; }
Scalar::Util's reftype can be used instead of ref if you wish to traverse objects.
In Section
Seekers of Perl Wisdom