sub test_xml_writer { my( @array, $aref ); my $io = new IO::File 'getline( $io ); $#{ $aref } > -1 ? push @array, $aref : last; } $io->close(); $io = new IO::File '>test-out.xml' or die "Could not open output file"; my $w = new XML::Writer( OUTPUT => $io, DATA_MODE => 1, DATA_INDENT => 2 ); $w->xmlDecl( undef , 1 ); $w->startTag( 'assets' ); foreach ( @array ) { $w->startTag( 'machine' ); my @c = qw( name ip_address snmp_community grbr model_serial ); local *a = $_; # my @a = @{$_}; $w->dataElement( $c[0], $a[0], src => 'netview' ) if defined $a[0]; $w->dataElement( $c[1], $a[1] ) if defined $a[1]; $w->dataElement( $c[2], $a[2], type => 'rw' ) if defined $a[2]; $w->dataElement( $c[3], $a[3], src => 'data' ) if defined $a[3]; $w->dataElement( $c[4], $a[4], src => 'data' ) if defined $a[4]; $w->endTag(); } $w->endTag(); $w->end(); $io->close(); }