Du bist hier: Snippet-Verzeichnis » Perl (198)
Sprache:

Alphabetical XML

Sprache: English
Programmiersprache: Perl
Veröffentlicht von: blackspyder [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1096


Beschreibung

this sorts an XML list of folder names (or whatever you want) alphabetically and displays them...

Code

1 #!/usr/bin/perl 2 3 # open your XML file 4 open(FH, "<folders.xml"); 5 6 while(<FH>) 7 { 8 # if there's a <folder></folder> tag, get the 9 # data, call it $name, and add it to a hash 10 # you can change the tags, of course ;] 11 if(($name) = $_ =~ /folder\>(.*)\<\/folder/i) 12 { 13 $names{"$name"} = $name; 14 } 15 } 16 17 close(FH); 18 19 # sort the hash alphabetically and put the keys in a new array 20 @keys = sort {$a cmp $b} keys %names; 21 22 # run through the array and print the values, which just happen 23 # to be the alphabetically sorted XML list... 24 foreach (@keys) 25 { 26 print $_ . "\n"; 27 } 28

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS