Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: XML::Twig output to filehandle

by eff_i_g (Curate)
on Feb 12, 2009 at 22:02 UTC ( [id://743465]=note: print w/replies, xml ) Need Help??


in reply to XML::Twig output to filehandle

I modified the input to consolidate the information, but the same concept applies:
use warnings; use strict; use XML::Twig; undef $/; my $XML = <DATA>; open my $OUT, '>', '/tmp/twig_out' or die "Can't open file: $!"; my $twig = XML::Twig->new( twig_handlers => { name => sub { ### If you want the text. if (1) { print $OUT $_->text(), "\n"; } ### If you want the elements. else { $_->print($OUT); } } } ); $twig->parse($XML); close $OUT or die $!; __DATA__ <script type="ApplicationPerspective" version="5.3.13.179" recorder="8 +.6.59.276" sav="25" guid="296A95D0-E8B6-4989-AA21-126796A3AD3F" xmlns +="http://www.keynote.com/namespaces/tstp/script"> <name> <![CDATA[GT Amadeus]]> </name> <actions> <action FrameErrorFatal="1" MetaErrorFatal="1"> <name> <![CDATA[Home Page]]> </name> <description> <![CDATA[]]> </description> </action> </actions> </script>

Replies are listed 'Best First'.
Re^2: XML::Twig output to filehandle
by poolpi (Hermit) on Feb 13, 2009 at 08:30 UTC

    When modifying special variables, it's a good idea to localize them and shorten the scope.

    See perlvar

    Update:
    I was thinking of $/


    hth,
    PooLpi

    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

      If you are talking about $_ in the handler, it _is_ localized (and set) by XML::Twig, so no worries there.

        I think its $/ from
        undef $/; my $XML = <DATA>;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-20 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found