Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


    In reply to Excel-like sort for multiple fields unix 'ls -l' output by cmv

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



    • Are you posting in the right place? Check out Where do I post X? to know for sure.
    • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
      <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
    • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
    • Want more info? How to link or How to display code and escape characters are good places to start.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others meditating upon the Monastery: (3)
    As of 2024-04-16 06:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found