Search code examples
xmlperlxml-simple

How can I save XML data to a file with XML::Simple?


I'm using XML::Simple package to import an XML file and change a few properties of some of the child tags. The change is visible when the data is dumped with:

 print Dumper($data);

But how can I write this edited data into a new XML file? I did go through the CPAN page, but some code regarding this would really help.


Solution

  • my $ref = XMLin(...);
    
    # ...
    
    open my $fh, ">", $path or die "$0: open $path: $!";
    print $fh XMLout($ref);
    close $fh or warn "$0: close $path: $!";