Perl Programming Fundamentals
Test your knowledge of Perl programming language basics including file I/O, string manipulation, regular expressions, subroutines, and debugging.
Questions
Running your Perl scripts with a d switch will perform which task?
- Invoke the Perl debugger
- Disable the Perl debugger
- Disable breakpoints
- Display a stack trace
Which file test can be done to see if a file is a socket?
- -s
- -l
- -S
- -k
How can you include code from another file in your program?
- With the #include preprocessor command
- Adding the file’s directory to @INC and then passing the filename to require.
- Both A & B
- None of the above
What will the following statement return?
- grep(! /^ !/, @array);
- Every non empty list element
- Every list element that does not start with an exclamation mark.
- Every list element.
What is the default sort order in Perl?
- alphabetic
- numeric
- ASCII
- none of the above
Rather than using print, what is often used in Perl when formatting is important?
- printf
- format
- align
- show
If $string contains abcdefghijiklmdef , what will the following call return? rindex($string , "def", 11 );
- 14
- 3
- 4
- 15
Consider the following program code: %hash = (small => 8oz, medium => 16oz, large => 32oz); @keys = sort(keys(%hash)); for ($i = 0; $i < 3; $i++) { print($hash{$keys[$i]}\n); } What is the result of executing this program code?
- The code will fail at line 1 because a hash cannot contain both numeric and string data.
- The code will execute without error but will output nothing.
- The code will output the following: 32oz 16oz 8oz
- The code will output the following: large medium small
Which of the following will call a subroutine named "mom"?
- &mom
- $mom
- mom$
- %mom%
Which operator can be used to create private variables within a subroutine?
- native
- limited
- my
- regional
Within a loop, which operator jumps to the end of the loop but does not exit the loop?
- next
- last
- redo
- leave
To convert a timestamp into a format more readable by a user, which function should you use?
- bitwise
- localtime
- translate
- transform
What value do variables have before they are first assigned?
- undef
- null
- 0
- nil
Which Perl function is used to change the name of a file?
- nameas
- rename
- name
- now_known_as
Which of the following commands should be used to open a filehandle named KAREN to an existing file named sw?
- open KAREN ">sw";
- open KAREN, ">sw";
- open "sw" KAREN;
- open ">sw", KAREN;
Which command should be used to close the filehandle KAREN?
- close KAREN "sw";
- KAREN close;
- close KAREN;
- close &KAREN
25 Which Perl function can be used to identify the first found occurrence of a substring?
- find
- index
- locate
- allocate
Which function can be used to return such information about a file as its UID, GID, CTIME, etc.?
- file
- stat
- info
- mode
Which modifier can be used when matching in Perl to ignore case?
- s
- v
- i
- c
Which function can be used to break up a string into more than one part based upon a separator?
- chop
- split
- divide
- parse