It helps if you post a complete runnable script

#!/usr/bin/perl use strict; use warnings; use XML::Twig; use Time::Piece; my $file_to_read = 'input.xml'; my @elements_to_treat = qw(node1 node2 node3); delete_node(\@elements_to_treat); sub delete_node { my ($all_elements) = @_; my %handlers; for my $element (@$all_elements){ $handlers{$element} = sub { $_->delete() }; } my $dateLog = localtime->ymd('_'); my $file_to_write = $file_to_read.'-parsed_'.$dateLog.'.xml'; open my $fh_out, '>', $file_to_write or die "Could not open $file_to_write : $!"; $handlers{ '_default_' } = sub { $_[0]->flush($fh_out) }; my $twig = new XML::Twig( twig_handlers => \%handlers, pretty_print => 'indented', ); $twig->parsefile($file_to_read); close $fh_out; print "Created $file_to_write\n"; }
poj

In reply to Re^3: TWig handler generation -- dispatch table by poj
in thread TWig handler generation by nico38100

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.