Bootstrap FreeKB - Perl (Scripting) - XML::Twig output to a file
Perl (Scripting) - XML::Twig output to a file

Updated:   |  Perl (Scripting) articles

Let's say you want to create an XML file using XML::Twig. In this example, foo.xml is created.

#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;

my $twig = new XML::Twig;
$twig->parse('<?xml version="1.0" encoding="UTF-8" standalone="no"?><acme><name>Bugs Bunny</name></acme>');

my $file = "/path/to/foo.xml";

if (open my $fh, ">", $file) {
  $twig->print($fh);
  close $fh;
}
else {
  print "failed to open $file \n";
  exit 1;
}

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 31c985 in the box below so that we can be sure you are a human.