http://www.perlmonks.org?node_id=1163350

nnigam1 has asked for the wisdom of the Perl Monks concerning the following question:

Hello great monks. I am trying to sort a directory by file size. My plan is to create a script that performs a compare of two files irrespective of the name to find duplicate files in a directory or two different directories. I am using md5sum for the comparison, but do not want to waste time on generating the checksum if files are of different size, hence the sort. In my script, I am using the command
>>@sDir=sort {-s $a <=> -s $b } (readdir D1);
This works for the first two . and .. but after that I get the error "Use of uninitialized value in numeric comparison (<=>) at comps.pl line 5". I thought that I had this working, but now am not sure. Maybe my test folder had all numerical file names. Please help oh wise and wonderful monks.