Perl Test Answers



1. Context in Perl can be.
Answers:
• conditional, referenced, literal, null
• numeric, string, list, scala
• associative, numeric, scalar, sparse
• inary, string, list, scala
• Boolean, numeric, string, null

2. A label, in Perl, is.
Answers:
• a marker for the Perl interprete
• a heading
• a switch statement
• the name of an operator
• a component embedded in the code
3. How many times does the do statement allow you to execute the block of statements in a loop?
Answers:
• Does not allow you to execute statements in a loop
• At least once
• Twice
• Depends on the number of times specified
• An indefinite number of times
4. A directory handle.
Answers:
• is a program that handles your operating system
• is a link from your computer program to the directory on your file system
• does not have its own namespace
• cannot be considered equivalent to a file handle
• does not require the opendir function
5. A scalar variable can contain.
Answers:
• only one data item at a time
• several data items at a time, the number of which needs to be declared beforehand
• unlimited items
• two items at a time
• an array of data items
6. How are hash references created?
Answers:
• % $ reference
• $ reference = \ % hash;
• @ reference = \ % hash;
• % hash=$reference;
• $$reference= \ % hash;
7. How is an array assigned to an array?
Answers:
• @array1=@array[1...6];
• @array1=@array2;
• @array=(1, "string", 4,5, \@ array z);
• By creating another array object
• An array cannot be assigned to an array
8. Non-associative operators are those that.
Answers:
• do not bind at all
• change their associativity depending on the context
• do not show precedence
• ind themselves to whichever expression they are adjacent to
• do not associate the lvalue with the expression on the right
9. Dereferencing refers to:
Answers:
• accessing an array that contains a reference to another array
• removing the reference
• an undefined or empty reference
• accessing values referred to by Perl references
• a scalar variable that keeps track of where another variable is stored in memory
10. Context in Perl can be:
Answers:
• conditional, referenced, literal, null
• numeric, string, list, scalar
• associative, numeric, scalar, sparse
• inary, string, list, scalar
• Boolean, numeric, string, null
11. A scalar variable can contain:
Answers:
• only one data item at a time
• several data items at a time, the number of which needs to be declared beforehand
• unlimited items
• two items at a time
• an array of data items
12. Non-associative operators are those that:
Answers:
• do not bind at all
• change their associativity depending on the context
• do not show precedence
• bind themselves to whichever expression they are adjacent to
• do not associate the lvalue with the expression on the right

13. When are the environment variables created?
Answers:
• Each time you run a program
• When you save a program
• When you compile a program
• The first time you run a program
• When you run a program in the Unix command shell
14. What is meant by variable interpolation?
Answers:
• Exchanging the values of one variable with anothe
• Passing a variable as an argument to a function
• The process of making a variable part of the namespace table
• The process of assigning some value to a variable
• The process of interpreting characters in a string literal surrounded by double quotation marks
15. Scalar variables can contain.
Answers:
• numeric data
• string data
• either numeric or string data
• null values
• Boolean values
16. What should be the first character of a format code?
Answers:
• + or -
• x
• &
• %
• @
17. The bless operato
Answers:
• creates references to objects that are not named
• creates a link between the reference object and the class the object is created within
• contains the literal name of another variable
• eferences a subroutine
• efers to literals
18. What is the following code an example of?
    $hitCounter=sub {print "This page has been called $hits times";};
Answers:
• Anonymous array
• Anonymous hash
• Object reference
• Subroutine
• Anonymous subroutine
19. What is the following code an example of?

        $hitCounter=sub {print "This page has been called $hits times";};
Answers:
• Anonymous array
• Anonymous hash
• Object reference
• Subroutine
• Anonymous subroutine
20. Which of the following begins or ends a system command string in Perl?
Answers:
• font size=5>"</font
• font size=5>'</font
• font size=5><></font
• font size=5><!</font
• font size=5>`</font
21. The keyword 'my' is used to declare
Answers:
• comments
• are words
• default variables
• Lexical variables
22. The foreach loop is usually used to process.
Answers:
• arrays and hashes
• a block of statements a number of times
• lists
• multi-dimensional arrays
• namespaces
23. The s/// function.
Answers:
• substitutes one string for another string
• eturns the first position of a substring
• eturns the last position of a substring
• eturns the number of characters of a string
• eturns or modifies a substring
24. Which of the following can be used with the do statement?
Answers:
• A label modifie
• next
• while
• edo
• last
25. The s/// function:
Answers:
• substitutes one string for another string
• returns the first position of a substring
• returns the last position of a substring
• returns the number of characters of a string
• returns or modifies a substring
26. The following code is an example of which switch syntax option?
GetOptions("extension:s");
Answers:
• Sets the default syntax
• Allows the option to be negated
• Sets the input option to include a mandatory string argument
• Sets the input option to include a mandatory integer argument
• Sets the input option to include an optional string argument
27. The foreach loop is usually used to process:
Answers:
• arrays and hashes
• a block of statements a number of times
• lists
• multi-dimensional arrays
• namespaces
28. The bless operator:
Answers:
• creates references to objects that are not named
• creates a link between the reference object and the class the object is created within
• contains the literal name of another variable
• references a subroutine
• refers to literals
29. What does the abs_path method do?
Answers:
• Gets the current working directory
• Gets the absolute path of the paramete
• Gets the absolute path of the input paramete
• Gets the absolute path of the current working directory
• Gets the current paramete
30. An atom cannot be
Answers:
• a single character or digit, A-Z, a-z, 0-9
• an escaped meta-characte
• an escaped special meaning characte
• a regular expression enclosed in parenthesis
• a meta characte
31. Which of the following is not an alignment character?
Answers:
• |
• &
• #
32. Which of the following translation modifiers matches all characters that are not part of the search string?
Answers:
• d
• s
• c
• x
• z
33. The value assigned to an array cell must be.
Answers:
• a scalar value
• a variable value
• a scalar or a variable value that resolves to a scalar value
• null
• None of the above
34. Which of the following characters denotes a comment in Perl?
Answers:
• //
• #
• /*
• &
• *
35. What does the pop function do?
Answers:
• Takes elements off the end of an array
• Puts elements into the first cell index of an array
• Adds an element to the end of an array
• Takes elements off the first index of the array
• Modifies or deletes elements from the array
36. Which one of the following is a part of the if family of branching statements in Perl?
Answers:
• if
• if else
• if elsif
• if, if else, and if elsif
• None of the above
37. Which of the following loops is usually used to process arrays?
Answers:
• while
• until
• do
• for / foreach
38. Which of the following can replace if else?
Answers:
• ? :
• : ?
• ! :
• / ?
• ? /
39. Which of the following is not a rule for switches using the Getopt function?
Answers:
• Switches begin with a dash character (-)
• Switches that do not take a parameter are set to the value 0
• Switches that take a parameter may or may not have space between the switch name and the switch value
• Switches are not required to be in any orde
• Switches are case-sensitive
40. Of which of the following switch syntax options is the following code an example of?

        GetOptions("extension:s");
Answers:
• Sets the default syntax
• Allows the option to be negated
• Sets the input option to include a mandatory string argument
• Sets the input option to include a mandatory integer argument
• Sets the input option to include an optional string argument
41. What does @ARGV refer to?
Answers:
• The number of elements in an array
• An array loaded with the command-line arguments
• A file handle used when processing an array
• A file associated with a file handle
• The name of your program
42. What are bare words?
Answers:
• Comments with the # sign missing
• Improperly declared variables
• Operators
• Character strings without surrounding quotation marks
• Characters denoting a string
43. What does the following error indicate?


"Can't Locate Function in @INC"
Answers:
• You misspelled a function name
• The last line of the required file returned a zero or null value
• You forgot to type the comma after the first argument of a function
• Your code is using a function that has been replaced by a newer function
• You used an uninitialized value
44. Dereferencing refers to.
Answers:
• accessing an array that contains a reference to another array
• emoving the reference
• an undefined or empty reference
• accessing values referred to by Perl references
• a scalar variable that keeps track of where another variable is stored in memory
45. Which of the following is not true of labels?
Answers:
• A label can go on any line
• A label must begin with a character followed by any combination of letters or numbers that end with a colon
• Reserved words cannot be used as labels
• Labels are case sensitive
• A label performs the same function as the last command
46. Which of the following operators is associated with writing to a program?
Answers:
• +
• | filename
• filename |
47. Which of the following characters is the variable designator for scalar variables?
Answers:
• @
• %
• $
• *
• &
48. The syntax of the sort function without a special purpose sort subroutine is:
Answers:
• sort ( ) {$b cmp $a ;}
• lvalue=sort list
• $ name= ~tr/+/ /;
• sortDescending ( ) {$b cmp $a;}
• lvalue=sort subroutineName list;
49. Which of the following meta characters creates a single expression or atom?
Answers:
• { }
• ( )
• *
• +
• ?
50. What does the following compound assignment operator signify?


     | =
Answers:
• Exclusive OR the expression on the left of the operator with the expression on the right of the operator
• Logical OR the expression on the left of the operator with the expression on the right of the operator
• Left shift the expression on the left of the operator by the expression on the right of the operator
• Binary OR the expression on the left of the operator with the expression on the right of the operator
• Append the expression on the left of the operator with the expression on the right of the operator
51. Which of the following is not a feature of Perl?
Answers:
• Portability
• Interpreted language
• Compiled language
• Is used for CGI applications
• Was originally used to generate reports that tracked errors
52. Which of the following is not a type of reference variables?
Answers:
• Direct
• Constant
• Subroutine
• Numeric
• Symbolic
53. What does the switch syntax :f do?
Answers:
• It allows the option to be negated
• It sets the default syntax
• It sets the input option to include an optional real-number argument
• It sets the input option to include an optional integer argument
• It sets the input option to include a mandatory real-number argument
54. The syntax of assigning to an array cell is.
Answers:
• array=new Array(n);
• scalar=@array[cellIndex]
• @array[cellIndex]=scalar;
• $array[cellIndex]=scalar;
• $array[n]=newArray;
55. Which of the following pertains to IO: :Handle?
Answers:
• Base class for IO classes
• Interface to file-open functions
• Get the file descripto
• Interface to IO: : *classes
• Export file symbols
56. Which of the following operators has/have the highest precedence?
Answers:
• Increment/decrement
• NOT, escape, sign operator
• Dereference operator
• Exponential operator
• Parenthesis, function, quotation marks
57. Which of the following Getopt::Long Configuration variables refers to an internal error flag?
Answers:
• debug
• orde
• pass_through
• null
• error
58. The syntax of the heredoc operator is.
Answers:
• print >>heredoc - marker;
• print <<heredoc - marker;
• select <<heredoc - marker;
• print << heredoc -label;
• printlist <<heredoc -label;
59. Which of the following file functions gets the file descriptor of a file handle?
Answers:
• fcntl
• flock
• getc
• fileno
• link
60. Which of the following is not true regarding scalar variable names?
Answers:
• Variable names that begin with an underscore or an alphabet character may have any practical length
• The characters that follow variable names that begin with an underscore or alphabet character may be digits, underscores or alphabet characters
• If a variable name begins with a digit, it may be of any practical length but can contain only digits
• If a variable name begins with a non-alphanumeric character, it can only be one character long
• Variable names can contain spaces
61. What does Perl stand for?
Answers:
• Programmer's Extraction Report Language
• Practical Extra Reference Language
• Practical Extraction and Report Language
• Practical Evolving Report Language
• Practical Error Report Language
62. What does a print FILEHANDLE list do?
Answers:
• Prints to FILEHANDLE the data in list
• Prints the contents of the default special variable $_ to FILEHANDLE
• Prints to the default selected file handle the data in list
• Prints to the default selected file handle the contents of the default special variable $_
• None of the above
63. Which of the following parameters does the printf function take?
Answers:
• An output file handle which is optional
• A format string which can include the format codes
• The variables to be formatted
• All of the above
• Does not take any parameters
64. What does the directory function telldir do?
Answers:
• Changes the current directory
• Closes a directory handle
• Creates a new directory
• Opens a directory handle
• Gets a directory handle's current byte offset
65. What does the ord string function do?
Answers:
• Returns or modifies a sub string
• Translates a number into a characte
• Creates a delineated string from an input list
• Returns the number of characters in a string
• Converts ASCII characters into their numeric value
66. Which of the following executes the continue block of statements before returning execution to the top of the loop?
Answers:
• last
• edo
• less
• next
• lu
67. What does the following syntax indicate?

        $lvalue=join(delimiter, list);
Answers:
• Creates a single delineated string from an input list
• Translates a number into a characte
• Returns the first position of a substring
• Returns the number of characters in a string
• Returns the last position of a substring
68. To start the Perl debugger, what will you type at the command prompt?
Answers:
• perld
• DB<1
• perl errorMessage.pl-d
• perl -d filename.pl
• perl-w programName.pl
69. What does the pattern modifier m do?
Answers:
• Ignores the character case when matching the pattern
• Compiles the pattern and interprets it only the first time it occurs
• Treats the input string as if it were a single line
• Treats the input string as if it were multiple lines
• Allows a comment character in the pattern
70. Scalar variables can contain:
Answers:
• numeric data
• string data
• either numeric or string data
• null values
• Boolean values
71. An atom cannot be:
Answers:
• a single character or digit, A-Z, a-z, 0-9
• an escaped meta-character
• an escaped special meaning character
• a regular expression enclosed in parenthesis
• a meta character
72. What does the following syntax indicate?
$lvalue=join(delimiter, list);
Answers:
• Creates a single delineated string from an input list
• Translates a number into a character
• Returns the first position of a substring
• Returns the number of characters in a string
• Returns the last position of a substring
73. The value assigned to an array cell must be:
Answers:
• a scalar value
• a variable value
• a scalar or a variable value that resolves to a scalar value
• null
• None of the above