Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 taking refuge in the Monastery: (6)
As of 2014-12-29 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (185 votes), past polls