my @output =
map $_->[0],
sort{$a->[1] <=> $b->[1]}
map [$_,-s $_],
@array;
Can someone explain the code in more detail? I can’t get head or tail of it ..
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Read from the bottom up:
An array (of filenames, given later usage).
For each filename, get a reference to a two element anonymous array, with the first element being the filename and the second element, the byte size of the file. map returns a list of these array references.
Sort the list of array references by increasing file size.
Turn the list of array references back into a list of filenames, but now in sorted order.
Save the list in @output.
This is equivalent in function to:
but only gets the size for each file once instead of once per comparison done by the sort.