I don't know why Inshalla answer has been downvoted because XML::Generator & XML::Writer are both good modules for writing out XML.
Using the Whats on iTunes? spec you commented on then this is how it could look using XML::Generator:
use strict;
use warnings;
use XML::Generator;
my $x = XML::Generator->new( pretty => 2, conformance => 'strict' );
my $itunes_ns = [ 'itunes' => 'http://www.itunes.com/dtds/podcast-1.0.dtd' ];
say $x->xmldecl( encoding => 'UTF-8' );
say $x->rss(
$x->channel(
$x->title('All about Everything'),
$x->category( $itunes_ns, { text => 'Technology' },
$x->category( $itunes_ns, { text => 'Gadgets' } ),
),
$x->category( $itunes_ns, { text => 'TV & Film' } ),
),
);
This produces:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>All about Everything</title>
<itunes:category text="Technology">
<itunes:category text="Gadgets" />
</itunes:category>
<itunes:category text="TV & Film" />
</channel>
</rss>
To answer the "turn perl array into XML" then here is one example:
use strict;
use warnings;
use XML::Generator;
my $x = XML::Generator->new( pretty => 2, conformance => 'strict' );
my $itunes_ns = [ 'itunes' => 'http://www.itunes.com/dtds/podcast-1.0.dtd' ];
my @categories = ( { "Technology" => [ "Gadgets", 'Gizmo' ] }, "TV & Film" );
say $x->xmldecl( encoding => 'UTF-8' );
say $x->rss(
$x->channel(
$x->title('All about Everything'),
map { recurse( $_ ) } @categories,
),
);
sub recurse {
my $item = shift;
return $x->category( $itunes_ns, { text => $item } )
unless ref $item eq 'HASH';
my ($k, $v) = each %$item;
return $x->category( $itunes_ns,
{ text => $k },
map { recurse ( $_ ) } @$v );
}
Look at this previous SO question something a bit similar
/I3az/