Tutor Marked Assignment PL TMA-07
In a Nutshell - CIW Course Section 2 Part B
PL TMA-07 - CD Access Code: 18480
Q1. What is a filehandle?
- a) A reference to a file
- b) A file address
- c) The access rights to the file
- d) An I/O connection between a file and program
- e) A series of rules stipulating what should occur if a file is not opened correctly
Q2. The scalar $filename, the hash %filename, the array @filename, the label filename, and the filehandle FILENAME can not be used in the same script without danger of a name conflict.
- a) True
- b) False
Q3. Connect each file name prefix used in the open function with their correct function.
- a) No prefix
- b) <
- c) >
- d) >>
- e) +<
- f) +>
- 1) Open a file for reading and writing, truncating the file first.
- 2) Default - open a file for reading.
- 3) Open a file for writing.
- 4) Open a file for reading.
- 5) Open a file for appending.
- 6) Open a file for reading and writing.
Q4. Which of these functions is commonly used if the opening of the file is not successful?
- a) kill
- b) close
- c) exit
- d) die
Q5. What will be displayed by the following Perl statements?
open (DATA, "+=data.txt");
print (DATA "where am I\n");
close (DATA);
- a) Where am I
- b) An error message
- c) +>data.txt
- d) Nothing
Q6. Which of these statements will point the cursor 2 bytes before the end of the file used in the previous question?
- a) seek (DATA, -2, 1);
- b) seek ("data.txt", 2, 2);
- c) seek (DATA, -2, 2);
- d) seek (DATA, 0, 2);
- e) seek ("data.txt", -2, 0);
Q7. Connect the following file test operators with their correct function.
- a) -s
- b) -f
- c) -d
- d) -B
- e) -r
- f) -z
- g) -T
- h) -e
- i) -W
- 1) Returns true if the file is a binary file.
- 2) Returns true if the file exists and has a non-zero size.
- 3) Returns true if the file is a plain file.
- 4) Returns true if the file has a size of zero.
- 5) Returns true if the file is writable.
- 6) Returns true if the file is a directory.
- 7) Returns true if the file exists.
- 8) Returns true if the file is readable.
- 9) Returns true if the file is a text file.
Q8. The stat function returns a list of data concerning a particular file. How many elements are in this list?
- a) 10
- b) 11
- c) 12
- d) 13
Q9. Which of the following statements related to environmental variables are true and which are false?
- a) Environmental variables are available to all processes on the system that hosts Perl.
- b) Changes to environmental variables will affect any child processes that are spawned from the parent program.
- c) Environmental variables are the same on all platforms.
- d) Changes to environmental variables are persistent.
- e) It is possible to access environmental variables like a common hash.
- f) Environmental variables are suitable for passing variables between different programs.
Not sure what these "environmental" variables are. I am familiar with "environment" variables as used in Windows and other operating systems.
Q10. What would be displayed by the following Perl statements on a Windows based computer?
print $ENV{"HOME"};
- a) The Windows directory.
- b) The IP address of the machine.
- c) The users' TEMP directory.
- d) The users' profile directory.
- e) Nothing
Q11. What would be displayed by the following Perl statements?
foreach $key (sort keys(%ENV)) {
print ("$key\t$ENV{$key}\n");
}
- a) The list of used variables.
- b) The list of security codes.
- c) The list of system information.
- d) The list of running processes.
- e) Nothing
Q12. Changing the $ENV{"PATH"} variable in a script can force the system to search directories that you specify.
- a) True
- b) False
Q13. What would be displayed by the following Perl statements if the program is run using perl program.pl -x -e -t?
$arg = $#ARGV + 1; $x = 1;
print "Count of arguments: " $arg. Arguments: ";
foreach (@ARGV) {
print "$_";
if ($x != $arg) { print ", "; }
$x++;
}
- a) Nothing
- b) Count of arguments: 3. Arguments: -x, -e, -t
- c) Count of arguments: 3. Arguments: -t, -e, -x
- d) Count of arguments: 4. Arguments: program.pl, -x, -e, -t
- e) Count of arguments: 4. Arguments: program.pl, -t, -e, -x
- f) Script error.
Q14. A filehandle can be defined either by an expression that evaluates to the filehandle name or by a ________?
- a) variable name
- b) static token
- c) string
- d) hash name
Q15. In Perl, it is convention to write filenames in uppercase letters.
- a) True
- b) False

