Monks-
I have the need to allow a GUI user to select various ways to sort multi-line text output from a (SunOS based) 'ls -l' command (think auto-sort on excel).
Given the ls format as follows:
2 drwxr-x--- 2 myuser mygroup 512 Jun 14 09:20 filename
In my opinion, they may choose to sort on any field except file permissions (but then again...), here's a list from right-to-left (as I understand them) and how they should be sorted:
filename - alphabetic
timestamp - oldest to newest
#ofBytes - numeric
group - alphabetic
user - alphabetic
#ofLinks - numeric
filePermissions - ??
#ofBlocks - numeric
I have all the data in a list (it comes from a remote host, so I can't access the file information directly from perl).
My current plan is to create a sub that is called like this:
@sorted = fileSort($field, @data);
This sub should be smart enough to do the right thing when sorting the various fields. I'm looking for advice on how to design it (or pointers to an existing sub that does this, or CPAN modules that may be helpful).
So far, my investigations initially led me to Sort::Fields which gives me a nice framework to do field sorting on a list of text, but would break down on the timestamp stuff (I could pre-process that to shoehorn it to work with this module).
Am I on the right track here, or is there something better I should be considering? I have some fears about the following:
timestamp - sorting this will be the biggest headache, I first need to collect all the correct "fields" that make up the timestamp, then need to change the variable ways that ls prints timestamps back into EPOCH time (using Date::Calc?) for numerical sorting, then put the initial text back in the final sorted list.
filename - Typical filename fears: what about goofy characters (spaces, non-ascii, etc).
group/user - Do I have the same problem here with goofy characters?
filepermissions - Ok, if I talk myself into allowing the user to sort on this, what way should it be sorted?
Any thoughts or suggestions are appreciated!
Thanks
-Craig
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.