Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Sort n Create XML

by Samy_rio (Vicar)
on Aug 20, 2007 at 09:12 UTC ( #633747=note: print w/ replies, xml ) Need Help??


in reply to Sort n Create XML

TIMTOWTDI using split and RegExp

use strict; use warnings; my $data = do{local $/; <DATA>}; my ($header, $class, $footer) = $data =~ m/^(.*<\/header>)(.*)(<footer +>.*)$/is; my @data = split/(?=<class>)/, $class; my %hash; for my $data (@data){ if ($data =~ m/<strength>((?:(?!<\/strength>).)*)<\/strength>/si){ my $str = $1; if (defined($hash{$str})) { $hash{$str} .= $data }else{ $hash{ +$str} = $data} } } my @sort = sort{$a <=> $b} (keys %hash); print "$header\n"; print $hash{$_} for (@sort); print "$footer"; __DATA__ <?xml version="1.0" encoding="UTF-8"?> <system> <header></header> <class> <name>Eight</name> <strength>8</strength> </class> <class> <name>Four</name> <strength>4</strength> </class> <class> <name>Ten</name> <strength>10</strength> </class> <class> <name>One</name> <strength>1</strength> </class> <footer></footer> </system>

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';


Comment on Re: Sort n Create XML
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://633747]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2015-07-30 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls