I took your Template as the "sorting rules". Shuffled that array, then applied the sorting rules to arrive back at the input array. I have no idea of what you are trying to do. Your description was not understandable to me. But Perl can re-order (order) anything as long as you can describe what the ordering rules are.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use List::Util qw(shuffle); my $sort_order=<<END; unitname tooltip verbosetooltip race buildtime officercost crewcost dilithiumcost latinumcost metalcost biomattercost maxHealth curHealth healthrate maxshield curShield shieldrate maxSpecialEnergy specialEnergyRate specialenergydisplaymode END #generate sorting rules... my $i=0; my %sort_order = map{$_ => $i++}split ' ',$sort_order; my @keys = shuffle keys %sort_order; # shuffle not really needed, # but adds some credibility as to # the random nature of output print "SHUFFLED ARRAY...\n"; # randomized array print join("\n",@keys),"\n"; print "\n","RE-ORDERED ARRAY BY SORTING RULES\n"; print "THIS IS NOT A COPY OF THE INPUT ARRAY\n"; @keys = sort{$sort_order{$a} <=> $sort_order{$b}}@keys; print join("\n",@keys),"\n"; __END__ SHUFFLED ARRAY... shieldrate officercost maxHealth race curHealth metalcost curShield verbosetooltip latinumcost healthrate biomattercost unitname dilithiumcost maxSpecialEnergy specialenergydisplaymode tooltip specialEnergyRate buildtime crewcost maxshield RE-ORDERED ARRAY BY SORTING RULES THIS IS NOT A COPY OF THE INPUT ARRAY unitname tooltip verbosetooltip race buildtime officercost crewcost dilithiumcost latinumcost metalcost biomattercost maxHealth curHealth healthrate maxshield curShield shieldrate maxSpecialEnergy specialEnergyRate specialenergydisplaymode Process completed successfully
In reply to Re: re-ordering lines of text in a file?
by Marshall
in thread re-ordering lines of text in a file?
by moddingforfun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |