#!perl -w # adopt perl's path to your environment. use strict; use Data::Iterator; # assuming you put it into # your [site/]lib/Data- #directory # Create a datastructure: my %data = (a => 1, b => [ qw(b1 b2 b3) ], c => {c1 => sub {return qw(first second third)}, c2 => undef, c3 => 'val_of_c3' } ); ## Create an Iterator-object: my $dobj = new Data::Iterator (\%data) || die "Oops. Creation of Iterator-object failed: $!"; ## Now let's get all the names + values... while (my ($path, $val) = $dobj->element) { print "all data: path: $path, value: $val\n"; # or whatever is to be done with $path, $val :-) } # ...and prepare for a new loop, if necessary: $dobj->reset; # ... ## Lookup data in $data{'c'}... while (my ($path, $val) = $dobj->element('{c}*')) { # note the asterisk! print "just {c}: path: $path, value: $val\n"; # or whatever is to be done with $path, $val :-) } # ...and prepare for a new loop, if necessary: $dobj->reset('{c}'); # ... ## Just retrieve a single value... my $distinct_val = $dobj->element ('{b}[1]'); ## ...or set a value (autovivificates data element, if necessary) my $old_val_of_b_1 = $dobj->element ('b.1', 'A New Value!'); # Now let's get all the keys: print "\nKeys: \n", join "\n", $dobj->keys; # ...and the values: print "\nValues: \n", join "\n", $dobj->values; ## Lookup a file's content... my $fobj = new Data::Iterator ('-FILE:C:\path\to\file.ext') || die "Oops. Creation of Iterator-object failed: $!"; while (my ($path, $val) = $dobj->element) { print "path: $path, value: $val\n"; # or whatever is to be done with $path, $val :-) } ## ...OR: open (FH, '< C:\path\to\file.ext') || die "Oops. Could not open file: $!"; $fobj = new Data::Iterator (\*FH) || die "Oops. Creation of Iterator-object failed: $!"; # ...