Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: XML::Twig prev_sibling

by mirod (Canon)
on Oct 20, 2011 at 16:50 UTC ( #932721=note: print w/replies, xml ) Need Help??

in reply to XML::Twig prev_sibling

It looks to me like any mention of 'now' in the parent (maybe excluding children of the parent) would make the entry not rare. So I would check just that: whether you can match 'now' in the parent's text.

You can test your code by building a quick test environment like the one below, that will let you add headers and check that your sub behaves properly:

#!/usr/bin/perl use strict; use warnings; use XML::Twig; use Test::More; XML::Twig->new( twig_handlers => { header => \&test_header }) ->parse( \*DATA); done_testing(); sub test_header { my( $t, $header)= @_; is( $header->att( 'expected'), is_la_rare( $header), $header->spri +nt); } sub is_la_rare { my $elt = shift; foreach my $label ($elt->children('la') ) { next unless $label->text eq "rare"; my $isNowRare = 0; if ( $label->parent->text_only =~ m/[nN]ow / ) { $isNowRare = +1; } if ( !$isNowRare ) { return 1; } } return 0; } __DATA__ <tests> <header expected="1"><la>rare</la></header> <header expected="0">Now <la>rare</la></header> <header expected="0">Now <la>hist.</la> and <la>rare</la></header> </tests>

And it looks like was down, it's back to life now, !@#$%^&* networks! Sorry for the inconvenience

Replies are listed 'Best First'.
Re^2: XML::Twig prev_sibling
by mertserger (Curate) on Oct 21, 2011 at 09:09 UTC
    Thanks Mirod! I'll try that and see if it does what I need.
    Thanks for getting back up too - I would have tried to sort this out for myself using its guidance but alas it was down yesterday!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932721]
[james28909]: it would be to much work just to get around renaming three subs lol
[james28909]: but you could put it all in one sub and return the same data type that was inputted. i could write a small example maybe
[Lady_Aleena]: Their uses are also vastly different.
[Lady_Aleena]: The first two make hashes and arrays from a file, the third returns data from a pre-existing hash.
[Lady_Aleena]: Well, HoH and AoH respectively.
[Lady_Aleena]: But if you want to play, play. I don't mind. 8)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2017-05-24 05:06 GMT
Find Nodes?
    Voting Booth?