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.

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) {
  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


Add a Comment

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