-
-
26 Sep 2009 17:54:08 UTC
- Distribution: Hash-Path
- Module version: 0.02
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (2)
- Testers (2649 / 0 / 0)
- Kwalitee
Bus factor: 0- 96.00% Coverage
- License: unknown
- Activity
24 month- Tools
- Download (3.17KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- Test::More
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Hash::Path - A simple way to return a path of HoH
VERSION
0.02
SYNOPSIS
use Hash::Path; my $hash_ref = { key1 => { key2 => { key3 => 'value', }, }, }; my $wanted = Hash::Path->( $hash_ref, qw{key1 key2 key3} ); # $wanted contains 'value'
DESCRIPTION
This module was written as proof of concept about how to find data inside a hash of hashes (HoH) with unknown structure. You can think that as hierarchical data like LDAP does, so our
path
could be the exactly the same as LDAP'sdn
, but a bit simpler because we (at least at this moment, who knows) don't want to deal with that.This is a perfect companion for traversing YAML:
use Hash::Path; use YAML; my ($hash_ref) = Load(<<'EOF'); --- name: john permissions: some-module: - read - write - execute another-module: - read EOF my $permissions = Hash::Path->get($hash_ref, qw(permissions some-module)); # $permissions contains [ 'read', 'write', 'execute' ]
API
- get
-
$scalar = Hash::Path->get($hash_ref, @path);
This is the only available method. It traverses the hash reference using the supplied path array, returning the value as scalar value.
- hash_path
-
use Hash::Path qw(hash_path); $scalar = hash_path($hash_ref, @path);
Now you can export the
hash_path
function to be a bit shorter. The parameters it takes are the same asget
.
ACKNOWLEDGEMENTS
Thanks to Arthur Axel "fREW" Schmidt "<FREW@cpan.org>" for using this module and suggesting a better implementation for the
get()
method.AUTHOR
Copyright (c) 2007, Igor Sutton Lopes "<IZUT@cpan.org>". All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install Hash::Path, copy and paste the appropriate command in to your terminal.
cpanm Hash::Path
perl -MCPAN -e shell install Hash::Path
For more information on module installation, please visit the detailed CPAN module installation guide.