Try
poj#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $header='u_ci_id,u_display_name,name,fqdn,ip_address,mac_address'; my $field = $ARGV[0] || 'u_ci_id'; my $input_xml = do { local $/; <DATA> }; my $twig = new XML::Twig; $twig->xparse($input_xml); my $root = $twig->root(); my @data = (); my @cols = split ',',$header; unshift @cols, $field; # added for sort for my $record ($root->children) { push @data,[ map { $record->first_child($_)->text } @cols]; } my @sorted = sort { $b->[0] cmp $a->[0] } @data; print $header."\n"; for (@sorted){ print join ',',@$_[1..$#cols]; # exclude sort col print "\n"; } __DATA__ <?xml version="1.0" encoding="UTF-8"?> <response> <result> <fqdn>fqdnB</fqdn> <ip_address>ip1</ip_address> <u_display_name>display1</u_display_name> <name>name1</name> <mac_address>mac5</mac_address> <u_ci_id>id 1</u_ci_id> </result> <result> <fqdn>fqdnA</fqdn> <ip_address>ip2</ip_address> <u_display_name>display2</u_display_name> <name>name2</name> <mac_address>mac4</mac_address> <u_ci_id>id 2</u_ci_id> </result> </response>
In reply to Re: Need help with node names for creating header line
by poj
in thread Need help with node names for creating header line
by vlturner
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |