Data::Rmap

Recursive map, apply a block to a data structure
Download

Data::Rmap Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • Brad Bowman
  • Publisher web site:
  • http://search.cpan.org/~bowmanbs/Regexp-Genex-0.07/lib/Regexp/Genex.pm

Data::Rmap Tags


Data::Rmap Description

Recursive map, apply a block to a data structure Data::Rmap is a Perl module to recursively evaluate a BLOCK over a list of data structures (locally setting $_ to each element) and return the list composed of the results of such evaluations. $_ can be used to modify the elements.Data::Rmap currently traverses HASH, ARRAY, SCALAR and GLOB reference types and ignores others. Depending on which rmap_* wrapper is used, the BLOCK is called for only scalar values, arrays, hashes, references, all elements or a customizable combination.The list of data structures is traversed pre-order in a depth-first fashion. That is, the BLOCK is called for the container reference before is it called for it's elements (although see "recurse" below for post-order). The values of a hash are traversed in the usual "values" order which may affect some applications.If the "cut" subroutine is called in the BLOCK then the traversal stops for that branch, say if you "cut" an array then the code is never called for it's elements (or their sub-elements). To simultaneously return values and cut, simply pass the return list to cut: cut('add','to','returned');The first parameter to the BLOCK is an object which maintains the state of the traversal. Methods available on this object are described in "State Object" below.SYNOPSIS $ perl -MData::Rmap -e 'print rmap { $_ } 1, , \\4, "\n"' 1234 $ perl -MData::Rmap=:all rmap_all { print (ref($_) || "?") ,"\n" } \@array, \%hash, \*glob; # OUTPUT (Note: a GLOB always has a SCALAR, hence the last two items) # ARRAY # HASH # GLOB # SCALAR # ? # Upper-case your leaves in-place $array = ; $hash = { key => "a value" }; rmap { $_ = uc $_; } $array, $hash; use Data::Dumper; $Data::Dumper::Terse=1; $Data::Dumper::Indent=0; print Dumper($array), " ", Dumper($hash), "\n"; # OUTPUT # {'key' => 'A VALUE'} # Simple array dumper. # Uses $self->recurse method to alter traversal order ($dump) = rmap_to { return "'$_'" unless ref($_); # scalars are quoted and returned my $self = shift; # use $self->recurse to grab results and wrap them return ''; } ARRAY|VALUE, , 4 ] ], 5 ]; print "$dump\n"; # OUTPUT # , '4' ] ], '5' ] Requirements: · Perl


Data::Rmap Related Software