Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Iterating arbitrary data structure

by perlphx (Initiate)
on Aug 28, 2008 at 02:58 UTC ( [id://707372]=perlquestion: print w/replies, xml ) Need Help??

perlphx has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: Iterating arbitrary data structure
by ikegami (Patriarch) on Aug 28, 2008 at 04:04 UTC

    What do you plan on doing with such an iterator? It seems like a solution in search of a problem.

    Note that Data::Dumper and/or Storable probably have the most complete and most resilient code for iterating over a data structure. If I'd write the iterator you want, I'd base it on the code from those modules.

Re: Iterating arbitrary data structure
by Fletch (Bishop) on Aug 28, 2008 at 03:04 UTC

    Perhaps Data::Diver?

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Iterating arbitrary data structure
by gaal (Parson) on Aug 28, 2008 at 05:23 UTC
Re: Iterating arbitrary data structure
by Anonymous Monk on Aug 28, 2008 at 03:01 UTC
    no struct's

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://707372]
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found