#!/usr/bin/perl -w # Read from standard input a list of filenames, and # report a sorted list of extensions and filenames # (most common ones first). # The format is "name count", where "count" is the number of appearances. # "name" usually begins with a "." followed by the name of the extension. # In the case where the filename has no extension, the name begins with "/" # followed by the entire basename. %extensions = (); while (<>) { if (m/\.([^.\/]+)$/) { $type = $1; chomp($type); $type = ".$type"; if (defined($extensions{$type})) { $extensions{$type}++; } else { $extensions{$type} = 1; } } elsif (m!/([^/]+)$!) { $filename = $1; chomp($filename); $filename = "/$filename"; if (defined($extensions{$filename})) { $extensions{$filename}++; } else { $extensions{$filename} = 1; } } } foreach $entry (sort {$extensions{$b} <=> $extensions{$a}} keys %extensions) { print "${entry} $extensions{$entry}\n"; }