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:
Wheras another user may abbreviate the names and not bother whith hyphens e,g.Rack1-Unit1 Rack1-Unit2 Rack3-Unit1 etc...
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |