perl - Working with child nodes in subroutine (XML::LibXML) -
I parse some XML data in my small code, but since I need the same thing in 3 places , Then I would like to make a suboutine for every time but I need to pass the current node which I am working as an argument, beyond reaching the current node's hair nodes beyond its current skill.
Here is an example of my code:
foreach $ day ($ doc-> SearchNode ('/ my / current / path')) {@atts = $ Day-> GetAttributes (); Foreach $ at (@atts) {$ na = $ at- & gt; GetName (); $ Va = $ at- & gt; GetValue (); If ($ va eq "Today") {# ------ My double code starts here ----- foreach $ cheese ($ day- & gt; SearchNode ('child_nodes_im_looking_for')) {# - --- Do a lot of things} # ------ My double code ends -----} If ($ va eq "tomorrow") {#same repeat code} if ($ va eq "some_other_day" ) {# Once repeated code .... again) for the second day ... do not do anything
How do I pass my current node into subroutine so that I can directly Can your hair nodes enter the routine?
I believe that you have harden
and Use warnings
in effect? Even if you have, you should declare your variable as my
as late at its first point of use as ideally as possible. .
I'm not clear what the problem really is, on its face, you have to give node $ day
as a normal subtraction parameter.
This reconfiguration shows your code sample. If I have been misinterpreted to you then please say so.
For my $ day ($ doc- & searchnode ('/ my / present / path')) {my @atts = $ day-> GetAttributes (); For my $ et (@ts) {my $ na = $ att-> GetName; My $ va = $ et- & gt; GetValue; If ($ va eq 'today') {barrind ($ day); } If ($ va eq 'tomorrow') {barrind ($ day); } If ($ va eq 'some_other_day') {barrage ($ day); } # For the second day ... do not do anything}} sub-repeated {my ($ node) = @_; My $ cheese ($ node- & gt; search node ('child_nodes_im_looking_for')) {# ----- do a lot of things}}
Comments
Post a Comment