Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Adjacency List Processing in XML::Twig

by japhy (Canon)
on Aug 18, 2001 at 16:55 UTC ( #105910=note: print w/ replies, xml ) Need Help??


in reply to Adjacency List Processing in XML::Twig

I'd change the double-grep (which also happens to be a nested grep) to a grep-map:

grep { $_->text eq $search_text } map { $_->children } @data; # or grep $_->text eq $search_text, map $_->children, @data;

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;


Comment on Re: Adjacency List Processing in XML::Twig
Download Code
Re: Re: Adjacency List Processing in XML::Twig
by chipmunk (Parson) on Aug 18, 2001 at 17:50 UTC
    Changing the nested grep to a grep map would change the semantics of the code.
    grep { grep { $_->text eq $search_text } $_->children } @data;
    This nested grep returns a list of elements for which any child contains the search text.
    grep { $_->text eq $search_text } map { $_->children } @data;
    This grep map a list of individual children that contain the search text.

     

    With a search for 'menlo park', the nested grep returns two elements; one has the children '<city>menlo park</city>' and '<city>palo alto</city>', and the other has the children '<city>atherton</city>' and '<city>menlo park</city>'.

    The grep map, on the other hand, would just return '<city>menlo park</city>' and '<city>menlo park</city>'.

      Oh, right. Sorry, princepawn, I misconstrued the purpose of that part of the code. That was silly of me.

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://105910]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2014-04-19 21:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls