Consider the directory listing below:
[perkins][lab2-2][~/Quiz1] ls -l total 12 -rw------- 1 perkins 17260 25 Feb 12 10:28 Apple.txt -r-------- 1 perkins 17260 25 Feb 12 10:28 Banana.txt ---x------ 1 perkins 17260 47 Feb 12 10:29 Chew.pl [perkins][lab2-2][~/Quiz1] cd .. [perkins][lab2-2][~] cd Quiz1Backup [perkins][lab2-2][~/Quiz1Backup] ls -l total 12 -rw------- 1 perkins 17260 25 Feb 12 10:32 Apple.txt -r-------- 1 perkins 17260 25 Feb 12 10:32 Banana.txt ---x------ 1 perkins 17260 47 Feb 12 10:32 Chew.pl [perkins][lab2-2][~/Quiz1Backup]
Describe what happens if you run the following Perl program:
$Count = 1; while ($Count < 10) { print "$Count\n"; $Count += $Count; $Count = $Count % 10; }
Describe what happens if you run the following Perl program, entering 2 as input? 3 as input? 4 as input? Describe what the program does in general, with a number N as input?
print "Enter a number: "; $Num = <>; chomp $Num; for ($Count=1; $Count<=($Num**2); $Count++) { if ($Count % 2) { print "X"; } else { print "O"; } if (($Count % $Num)==0) { print "\n"; } }
Write a Perl program that takes three strings as input and prints them out in increasing ASCII-betical order. (The same ordering used by the string comparison operations.) Write the program without using arrays and the "sort" operation, which we only covered in later classes. For example, runs of your program might look like:
[perkins][lab2-2][~/Quiz1] perl ThreeSort.pl Enter string 1: apple Enter string 2: banana Enter string 3: grape Sorted ASCII-betically: apple banana grape [perkins][lab2-2][~/Quiz1] perl ThreeSort.pl Enter string 1: grape Enter string 2: apple Enter string 3: banana Sorted ASCII-betically: apple banana grape [perkins][lab2-2][~/Quiz1] perl ThreeSort.pl Enter string 1: banana Enter string 2: Banana Enter string 3: Apricot Sorted ASCII-betically: Apricot Banana banana [perkins][lab2-2][~/Quiz1]
If x1, x2, ... , xN are a set of N numbers, recall that the (arithmetic) mean of the numbers is:
M = (x1+x2+...+xN)/N
and the standard deviation is
S = sqrt((x12+x22+...+xN2)/N - M2)
Write a Perl program that asks the user for how many numbers he would like to input, and then takes each of those numbers as input. After all the numbers have been input, your program should print out the mean and standard deviation of the numbers. Remember, this quiz doesn't cover arrays, so please write your program without the use of arrays. An example run of your program might look like:
[perkins][lab2-2][~/Quiz1] perl MeanStd.pl How many numbers would you like to enter? 4 Enter number 1: 1 Enter number 2: 5 Enter number 3: 2 Enter number 4: 3 The mean is 2.75 and the standard deviation is 1.4790199457749. [perkins][lab2-2][~/Quiz1]