Keep It Simple, Stupid | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Ok, based on what I've read here, the first thing that comes to mind to handle the date is to parse out the 3 fields that comprise the date. One factor that you may be missing is that in general, files older than a year don't show the time, instead they show like this: (from my Solaris workstation):
One option, at least on Solaris, (I don't know if all flavors of unix share this parameter) you can use -e to list the time in a standard format regardless of how old the file is: Now, that being said, you know what columns comprise the date, you can capture those (you can use split to separate by whitespace, then use columns 6, 7, 8, 9 for the date in this case) and build the date yourself into a format that Date::Calc (or whatever date function you want) can read. Once you get to that point, you should have all of the information you need to perform the sort functions that you like. I've never used Sort::Fields, but if its an easy framework to use, I'm sure it shouldn't be too difficult to set up to sort on whatever column you click on. For the data structure, again the first thing that comes to mind is an array of hashes. Each hash representing a line in the listing (or it could be an array of arrays, but I like having non-numeric keys) and the array would represent that directory's contents. I can't imagine a good reason for sorting on the permissions, but I suppose it could be done. They are alphanumeric characters, and are in order (r < w < x) to match the sequence shown. Doing queries to see if a file is executable,writable,etc could easily be done with a regex on field 2 (note in my listing on Solaris 10, the first field is the permissions, and second field are the links -- not sure why yours are different, haven't looked into it) but whether or not you want to do that is entirely up to you of course. Hope that helps! In reply to Re: Excel-like sort for multiple fields unix 'ls -l' output
by sierpinski
|
|