-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't select specific array item (question) #26
Comments
Not sure yet if I correctly understand what the criteria for 'street2' is. You already selected the [3] element, in which street2 appears. You could specify that criteria further like
But that's probably not helpful when you already know it in advance, so not sure... |
I want to select the 2nd array item, via index.
but this returns
while
How do I access the array refs first or second item so that I get this result?
|
Hm, that array containing [street1, street2] is the result of the dpath query, containing everything it found with the dpath somewhere in the data structure. So it's technically not in the data structure and therefore not addressable with the dpath. So you would query with a dpath like you quite did already:
and on the result choose the |
I cant use perl code to work with the dpath result, the query needs to return
is there no query that does that? |
Not on the result set. In dpath logic you need to express it from the point of view of the actual data structure. So you could early on in the path filter out the wrong indexes, like with
But still it all comes down to your knowledge about the result in advance. |
your solution doesnt work for our use case. I need to select all nodes from so 1st step should yield
what if the source data would look like this `["item1","item2"] is there no query that returns either "item1" or "item2" using an index? ps: I appreciate your help. |
I'm quite sure I understand your problem. However, whether that item you want to access is the n-th item depends on the data structure in which you search. You are looking at the result where that "street2" could result from anywhere in the data structure. That gives us 3 options:
I can see that you might have a restricted environment where you can only change the dpath but nothing else. But as you would have to change the dpath's index anyway to reach the 4th result, respectively any other index every time the input data structure changes, then why not do that at the beginning of the dpath as I suggested? Alternatively, maybe in your environment you can daisy-chain dpath operations and feed the result into the next with |
Actually, you already solved that "4th item problem" with your |
I will try with another example, because I am having a hard time putting my question into understandable words. :)
now select the 2nd item, I cant figure out how to do that, and I feel like I am running in a circle. :p ps: I suppose this is not a DPath issue but rather my mind not grasping how to use it. my apologies. I dont understand why I can filter out the nodes I want but after that I cant select a specific one by index. |
I absolutely understand your problem and I feel sorry to not have better answers. The answer to your last question is: dpath works on the nodes - not on its own result after that. But that is exactly what you want. You want a match on the result of a match so far. That's different data set than the actual input data structure. So maybe you can extend the application to accept two (or more) dpaths to allow a "chain" of dpath matching. The first does what you already do now. We could invent a syntax for DPath "chains", like |
One yould invent a "container syntax for dpath chains" which is easier to parse with the currently used balanced expression parser and even recognizable, like this:
but still: it doesn't exist yet and I'm really low on time and energy. |
I think I understood the modules constraints now and found a solution for my problem. namely, chaining two path executions as you advised. thank you for your effort to help me! |
Nice. Thanks for your patience. |
this prints
What path selects only one specific array item? For example, only
street2
.The text was updated successfully, but these errors were encountered: