Hi monks!
I am searching for a robust module that would provide a way to iterate through an arbitrary and complex data structure. I wrote a module that does this on my own (with speed and robustness problems), however, this seems like such a common task that I'm pretty sure that there HAS to be a nice, robust CPAN or core module that would do the thing.
The module I wrote works like this:
my $iter = StructIterator->new (
struct => $my_struct,
);
while ( $iter->next ) {
my $value = $iter->yield;
my $hash_key_or_array_index = $iter->index;
my $current_depth = $iter->level;
## ...
}
Basically I am looking for the same thing, only robust (handling of circ. refs, blessed refs,...) and fast. There is the Data::Walk module, but I didn't really like it that much - it is not really an iterator (you provide a callback coderefs), and I don't like the way it iterates over hashes - it yields a value for a key and the next callback will yield the value.
Does anybody know about something that would suit my needs? I looked all over the web and all I found was the Data::Walk module.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.