other monks have already suggested ways to do the "twisted sort", but have you considered just changing your data structures on the first place?
You are storing in the same array two kinds of unrelated information: a list of books and author ordering information. Using a magic marker is a bad idea almost every time.
In that case, the obvious data structures to use are an array to store book descriptions and a hash to store author ordering information.
If you are getting the information from a DB, the information should already be structured that way there. You should even be able to get the list of books ordered from the database!
If you are reading the information from a file (or from the network) you can build those two structures on the fly on the parsing phase with almost identical effort and then other parts of your code will become much cleaner.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.