CPAN::Forum
XML-Simple - XML::Simple Sorting
| Posted on Wed Nov 21 23:38:22 2007 by tirto |
| XML::Simple Sorting |
|
Hi,
i have a question regarding XML::Simple sorting. I am trying to sort the result of XMLout numerically. Here is my perl data structure:
my $hashref = {
item => {
"2" => { label => 'bar' },
"1" => { label => 'foo' },
"11" => { label => 'baz' }
}
};
my $xs = XML::Simple->new();
my $xml = $xs->XMLout( $hashref, KeyAttr => ['id'] );
print $xml;
and here is my output (it is sorted ascii-betically):
<opt>
<item id="1" label="foo" />
<item id="11" label="baz" />
<item id="2" label="bar" />
</opt>
i don't find any options for sorting, e.g. KeySort = \&some_function in the doc.
anyone can suggest what to do i want to sort by "id" numerically?
here is my expected output:
<opt>
<item id="1" label="foo" />
<item id="2" label="bar" />
<item id="11" label="baz" />
</opt>
thanks,
tirto
|
| Direct Responses: 6494 | Write a response |
(10)
]