#!/usr/local/bin/perl

### Subroutine 'numerically' for ordering the associative array
### by key order. If do simply a 'sort keys %array'
### will get a non-numerical, but alphabetical (even
### with numbers), ordering.

sub numerically { $a <=> $b }

# Script to list files in directory in order of decreasing size.

opendir(DIR,'.') || die "Can't open directory";
@filenames = readdir(DIR);
closedir(DIR);

foreach $file (@filenames)
{
	$size = -s $file;
	$var{$size} = $file;
}

foreach $key ( sort numerically (keys(%var)) )
{
	print $key,"\t",$var{$key},"\n";
}