Micro Station Technology, Inc.

Perl Language


Here is a code fragment in Perl, explain what this code fragment does?

sub checkargs()
{
$topdir = $ARGV[0];
if (!(-d $topdir && -w $topdir)) {
	print $topdir . $usage2;
	exit 2;
}

$dirdepth = $ARGV[1];
if ($dirdepth < 1) {
	print $dirdepth . $usage3;
	exit 3;
}

$dirwidth = $ARGV[2];
if ($dirwidth < 1 || $dirwidth > 10) {
	print $dirwidth . $usage5;
	exit 5;
}

$filewidth = $ARGV[3];
if ($filewidth < 1 || $filewidth > 20) {
	print $filewidth . $usage6;
	exit 6;
}

$filesz = $ARGV[4];
if ($filesz != 1024 && $filesz != 10240 && $filesz != 102400) {
	print $filesz . $usage4;
	exit 4;
}
}
 

Write a Perl script for this task in 20 minutes. You may wish to write down the pseudo-code first.

The Task: process a text file to separate out words, and count the number of occurrences for each word. Print out the count for word in sorted order. See the example input and output below:

(Unix Knowledge) Do this same task using simple Unix commands and scripts.

Input file example:

 fox jumps over fox
 There are over 3000 foxes there
 

Output file example:

 are=1
 fox=2
 foxes=1
 jumps=1
 over=2
 there=1
 There=1