Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: XML::Twig newbie question

by Jenda (Abbot)
on Sep 18, 2012 at 07:15 UTC ( #994210=note: print w/ replies, xml ) Need Help??


in reply to Re: XML::Twig newbie question
in thread XML::Twig newbie question

Another way would be to make the subroutine curried (that is expecting to get the parameters separately, not all at once):

foreach my $file (@files){ # set up the XML parser: my $twig= XML::Twig->new( twig_handlers => { topicref => topicref_processing($file), xref => topicref_processing($file) }, ); $twig->parsefile($file); $twig->purge; } sub topicref_processing { my ($file) = @_; return sub { my($twig, $topicref) = @_; my($atts) = $topicref->atts(); if($$atts{'keyref'}){ ### associate this keyref with $file } } }

Jenda
Enoch was right!
Enjoy the last years of Rome.


Comment on Re^2: XML::Twig newbie question
Download Code
Re^3: XML::Twig newbie question
by Anonymous Monk on Sep 18, 2012 at 07:31 UTC

    Another way would be to make the subroutine curried (that is expecting to get the parameters separately, not all at once):

    Sure, you could write your closure that way ( the schönfinkeling way), but it gains you nothing in this example, it just takes a little more memory

      Depends on the complexity of the subroutine. Maybe you do not want to include all that code in the middle of the loop. I would not sweat over the tiny difference in memory footprint or the cost of two additional subroutine calls. Use whatever makes the code easier to maintain.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

Re^3: XML::Twig newbie question
by slugger415 (Beadle) on Sep 18, 2012 at 15:50 UTC

    "Curried?" sounds delicious! :-) Never heard that phrase before.

    Thank you, this is a simple solution that works perfectly for me.

    Scott

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-07-30 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls