in reply to Need help with node names for creating header line
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::Twig; my $input_xml = '<?xml version="1.0" encoding="UTF-8"?> <response> <result> <u_service_catalog>true</u_service_catalog> <u_chg>false</u_chg> <virtual>false</virtual> <u_inc>false</u_inc> <u_ci_id>B</u_ci_id> </result> <result> <u_service_catalog>true</u_service_catalog> <u_chg>false</u_chg> <virtual>false</virtual> <u_inc>false</u_inc> <u_ci_id>C</u_ci_id> </result> <result> <u_service_catalog>true</u_service_catalog> <u_chg>false</u_chg> <virtual>false</virtual> <u_inc>false</u_inc> <u_ci_id>A</u_ci_id> </result> </response>'; my $field= $ARGV[0] || 'u_ci_id'; my $twig = 'XML::Twig'->new; $twig->xparse($input_xml); my $root = $twig->root; my @records = $root->children; my @sorted = sort { $b->first_child( $field)->text cmp $a->first_child( $field)->text } @records; for my $record (@sorted) { my @info_tags = $record->children; my @data; for my $info_tag (@info_tags) { push @data, [ $info_tag->name, $info_tag->text ]; } say join ',', map $_->[0] . ': ' . $_->[1], @data; }
push @data, [ $info_tag->name, $info_tag->text ]; stores a two element array to the @data, so when printing it, you have to dereference it (that's what $_->[0] and $_->[1] do).
Note that I removed the parts of the code irrelevant to the question. Using both XML::Twig and XML::LibXML in one program sounds very strange.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need help with node names for creating header line
by vlturner (Sexton) on Dec 30, 2015 at 20:33 UTC | |
by choroba (Cardinal) on Dec 30, 2015 at 20:43 UTC | |
by vlturner (Sexton) on Dec 30, 2015 at 21:08 UTC | |
by vlturner (Sexton) on Dec 30, 2015 at 21:19 UTC | |
by vlturner (Sexton) on Dec 30, 2015 at 21:28 UTC | |
by choroba (Cardinal) on Dec 30, 2015 at 22:43 UTC |