in reply to Re: •Re: Keeping only the $n newest files/directories in a diretory?
in thread Keeping only the $n newest files/directories in a diretory?
Makes a list of files in that directory. It's then used as the second argument to</var/script/proc/*>
which, from that list, generates a 2nd-order list, each element of which is a list containing in field one the filename, and in field two the modification time (-M is a test operator giving that -- it's default parameter is $_). If you're a C Programmer, think something like the following for each entry in that 2nd order list:map [$_, -M]
That structure is then used as an argument tostruct { char filename[FNSIZE]; int mtime; /* The date field -- modification time */ }
which sorts the first index of the 2nd-order list by the date field. The results are then used as the 2nd argument tosort { $a->[1] <=> $b->[1] }
which returns a 1d list containing just the filenames (although they're sorted this time). The results are then saved in @newest_first. Code like the above can be intimidating unless you know the map operator well. It's an extremely powerful tool once you do though, and is one of the ways in which Perl's expressiveness borrows from Lisp. Hope this helps.map $_->[0]
|
|---|