With Perl it is possible to re-order (sort) any list of stuff according to a set of sorting rules. Of course things like "a"<"b" are the easiest (letter a is less than letter b). But this can be arbitrarily complex.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.