The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Data::FetchPath - "eval"able paths to your complex data values


Version 0.02


Quick summary of what the module does.

    use Data::FetchPath 'path';
    use Test::Most;

    my $data = {
        foo => 3,
        bar => [qw/ this that 3 /],
        3   => undef,
        baz => {
            trois  => 3,
            quatre => [qw/ 1 2 3 4 /],
    my $target_value = 3;
    ok $paths = path( $data, $target_value ), 'Fetching paths for matching data should succeed';
    my @expected = sort qw(
    eq_or_diff $path, \@expected,
        '... and it should return all paths to data values found';
    for ( 0 .. $#expected ) {
        my $found_value = eval "\$data->$expected[$_]";
        is $found_value, $target_value,
            '... and all values should match the value you looked for';




Exported on demand via:

 use Data::FetchPath 'path';
 my $paths = path($data_structure, $value);
 my $paths = path($data_structure, $regex);

Passed a data structure and either a scalar value or a regex (qr/foo.*bar/), this function will return an array reference to the paths to said value. Each path is suitable for using eval against said data structure:

 my %data = (
     one   => 'uno',
     two   => 'dos',
     three => 'tres',
 # find values with the letter 'o' in them
 my $paths = path(\%data, qr/o/);
 foreach my $path (@$data) {
     print eval "\$data$path\n";

Currently the data structure must be an array or hash reference. The value must be a scalar or a regular expression.


Curtis "Ovid" Poe, <ovid at>


Please report any bugs or feature requests to bug-data-fetchpath at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Data::FetchPath

You can also look for information at:



Copyright 2008 Curtis "Ovid" Poe, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.