in reply to Re^3: Get newest folders inside directory
in thread Get newest folders inside directory

Hi,
This works great.
Can anybody explain how this works internally? i mean which executes first and which next, left to right etc. what is the input to sort? I am new to Perl.

Thanks
  • Comment on Re^4: Get newest folders inside directory

Replies are listed 'Best First'.
Re^5: Get newest folders inside directory
by BrowserUk (Patriarch) on Nov 10, 2010 at 08:22 UTC

    Read the comments in number order:

    ## which are finally assigned to the array ## 4 # +# my @newest = ( ## This runs next, and sorts the directories ## 2 +## ## from most recent to least recent sort{ -M $a <=> -M $b } ## this runs first, generates a list of files/dirs in root ## 1 +## ## which it then reduces to just a list of directories grep -d, glob '/*' )[0..19]; ## then this "list slice" selects the 20 most recent ## 3 # +#

    It is equivalent to:

    my @allFilesnDirs = glob '/*'; my @allDirs = grep -d, @allFilesnDirs; my @allDirsSortByDateTime = sort{ -M $a <=> -M $b } @allDirs; my @newest20 = @allDirsSortedByDateTime[ 0..19 ];

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.