Use the ->name method to retrieve the tag name.
#!/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,

In reply to Re: Need help with node names for creating header line by choroba
in thread Need help with node names for creating header line by vlturner

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.