Thank you very much for the info. I have tried the solution with eval and it works as I expect so I really appreciate it.

The reason for the requirement is as follows:

I have a web interface where users can manage their own population of STB hardware. Each STB is given a unique name (usually relating to it's position in a series of racks). On the interface, the STBs are listed along with details that relate to each unit. In Perl, the list is sorted by the most basic "sort" function.

Different users employ different naming schemes. For example one users list may look something like:

Rack1-Unit1 Rack1-Unit2 Rack3-Unit1 etc...
Wheras another user may abbreviate the names and not bother whith hyphens e,g.
R1U1 R2U3 R10U1 etc...

Users can call their STBs anything they want as long as each name is unique. The basic sort function is not ideal as when there are 10+ racks and 10+ units, Numbers in the teens are listed after number 1, instead of being listed in numeric order e,g. R1,R10,R11,R2,R3 etc...

What I want to do is allow users to build their own custom sort statements which they can store in a text file. The script that creates the list to be shown on the interface can then read that text file and sort the list according to the user. So if a user creates the below sort statement:

{ ($a =~ /R(\d+)/)[0] <=> ($b =~ /R(\d+)/)[0] or ($a =~ /U(\d+)/)[0] <=> ($b =~ /U(\d+)/)[0] } They will have their list ordered first by Rack, and then by unit e,g.
R1-U1 R1-U10 R2-U2 R3-U13 R10-U1 R10-U5 R10-U11

Being able to customise the sort order improves the usability of the interface for the users. They use it everyday for a majority of their work so anything that helps save time is of great value

The interface is deployed in different areas of a secure testing facility and is only used on a private VPN, so the access is tightly controlled.


In reply to Re^2: Create sort function from a text file by Doozer
in thread Create sort function from a text file by Doozer

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.