Skip Menu |

This queue is for tickets about the Data-DPath CPAN distribution.

Report information
The Basics
Id: 68882
Status: resolved
Priority: 0/
Queue: Data-DPath

People
Owner: Nobody in particular
Requestors: RUSSOZ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.43
Fixed in: (no value)



Subject: dpath( .. )->match() returning odd result for regex-based value search
run the attached script.

on a data struct defined as:
my $data = {
    aList => [qw/aa bb cc dd ee ff gg hh ii jj/],
    aHash => {
        apple  => 'pie',
        banana => 'split',
        potato => [qw(baked chips fries fish&chips mashed)],
    },
};
 
we try to pick the elements using the DPath expressions:
//*[ value =~ /i/ ]
//*[ value =~ /f/ ]

oddly enough, when the regex searches for /i/, the result include the entire hashref ponted to by the 'aHash' key in the first level. See output's excerpt below:


----- cut here  ----- cut here  ----- cut here  ----- cut here  ----- cut here  ----- cut here  ----- cut here  ----- cut here  -----
 ::: elements with letter 'i'
[
    [0] "split",
    [1] "pie",
    [2] "ii",
    [3] "chips",
    [4] "fries",
    [5] "fish&chips",
    [6] {               >>>>>>>> why this hashref is being returned here??? makes no sense
        apple    "pie",
        banana   "split",
        potato   [
            [0] "baked",
            [1] "chips",
            [2] "fries",
            [3] "fish&chips",
            [4] "mashed"
        ]
    }
]
::: elements with letter 'f'
[
    [0] "ff",
    [1] "fries",
    [2] "fish&chips"
]
----- cut here ----- cut here ----- cut here ----- cut here ----- cut here ----- cut here ----- cut here ----- cut here -----
 
Subject: test-data-dpath.pl
#!/usr/bin/perl use 5.010; use Data::Printer colored => 0; use Data::DPath qw/dpath dpathr/; my $data = { aList => [qw/aa bb cc dd ee ff gg hh ii jj/], aHash => { apple => 'pie', banana => 'split', potato => [qw(baked chips fries fish&chips mashed)], }, }; sub pick { my ( $caption, $dpath ) = @_; say '::: ' . $caption; my @res = dpath($dpath)->match($data); p @res; } # so say 'we all'; p $data; ############################################################################ pick( 'list', '/aList' ); pick( 'list element', '/aList/*[2]' ); pick( 'all 4th elements of all lists', '//*[3]' ); say '::: tweaking list element'; my @elem = dpathr('/aList/*[2]')->match($data); say @elem; ${ $elem[0] } = 'WAKAWAKAWAKA'; p @elem; pick( 'list after tweaking', '/aList' ); ############################################################################ pick( 'hash', '/aHash' ); say 'hash address: ' . $data->{aHash}; pick( q{elements with letter 'i'}, '//*[ value =~ /i/ ]' ); pick( q{elements with letter 'f'}, '//*[ value =~ /f/ ]' );
CC: bug-Data-DPath [...] rt.cpan.org
Subject: [rt.cpan.org #68882] Re: Odd behaviour in Data::DPath
Date: Thu, 16 Jun 2011 20:04:02 -0300
To: Steffen Schwigon <ss5 [...] renormalist.net>
From: Alexei Znamensky <russoz [...] gmail.com>
On 16 June 2011 19:45, Steffen Schwigon <ss5@renormalist.net> wrote: Show quoted text
> Alexei Znamensky <russoz@gmail.com> writes:
> > Hi Steffen, > > > > I just pinged you in IRC, but you are probably off for the day.
> > Strange, didn't notice it. Maybe my irssi-fu lacks skills… > > But indeed, I just stretched bedtime for that. I just answered for > completeness in irc, but I go to bed now. :-) > >
> > In the last two cases, filtering with regex for /i/ and for /f/ (or > > anything else, as far as I tested, which isn't much), I would expect > > only a list of string elements being returned.
> > I agree to your expectation. > > I just made it a test case but still need to investigate what happens. > Tomorrow. :-) > > Thanks for trying DPath and reporting the issue. >
As we chatted over irc, I have just opened a bug in RT: #68882 Copying RT for record tracking. I suppose you have received a notification from RT as well. Thanks for making this amazing module. It is a fantastic idea and I am glad that it was already in place (rather than having to write it myself) :-P Cheers! -- Alexei "RUSSOZ" Znamensky - russoz EM gmail com - http://russoz.org GPG fingerprint = 42AB E78C B83A AE31 7D27 1CF3 C66F B5C7 71CA 9F3C http://www.flickr.com/photos/alexeiz http://github.com/russoz
Hi! I think I fixed it. Please try again with 0.44, currently on its way to CPAN. Thanks for reporting. Kind regards, Steffen -- Steffen Schwigon <ss5@renormalist.net> Dresden Perl Mongers <http://dresden-pm.org/>