Perl Programming Fundamentals

Test your knowledge of Perl programming language basics including file operations, variables, loops, subroutines, string manipulation, and debugging.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

If $string contains abcdabcd , what will the following call return? index ($string, “cd”, 3);

  1. 6
  2. 4
  3. -1
  4. 2
Question 2 Multiple Choice (Single Answer)

Which operator can be used to access the first item in an array?

  1. shift
  2. start
  3. right$
  4. left$
Question 3 Multiple Choice (Single Answer)

Assume that $var has the value hello . What is the value of the following sting?qq(It’s time to say $var);

  1. It’s time to say $var
  2. It’s time to say hello
  3. Both
  4. None
Question 4 Multiple Choice (Single Answer)

Which modifier can be used when matching in Perl to match any character?

  1. S
  2. V
  3. I
  4. C
Question 5 Multiple Choice (Single Answer)

Which of the following operators work most like substitution?

  1. /f
  2. /g
  3. s///
  4. m//
Question 6 Multiple Choice (Single Answer)

Running your Perl scripts with a d switch will perform which task?

  1. Invoke the Perl debugger
  2. Disable the Perl debugger
  3. Disable breakpoints
  4. Display a stack trace
Question 7 Multiple Choice (Single Answer)

Which file test can be done to see if a file is a socket?

  1. -s
  2. -l
  3. -S
  4. -k
Question 8 Multiple Choice (Single Answer)

How can you include code from another file in your program?

  1. With the #include preprocessor command
  2. Adding the file’s directory to @INC and then passing the filename to require.
  3. Both A & B
  4. None
Question 9 Multiple Choice (Single Answer)

What will the following statement return?

  1. grep(! /^ !/, @array);
  2. Every non empty list element
  3. Every list element that does not start with an exclamation mark.
  4. Every list element.
Question 10 Multiple Choice (Single Answer)

What is the default sort order in Perl?

  1. alphabetic
  2. numeric
  3. ASCII
  4. none of the above
Question 11 Multiple Choice (Single Answer)

Rather than using print, what is often used in Perl when formatting is important?

  1. printf
  2. format
  3. align
  4. show
Question 12 Multiple Choice (Single Answer)

Which of the following will call a subroutine named "mom"?

  1. &mom
  2. $mom
  3. mom$
  4. %mom%
Question 13 Multiple Choice (Single Answer)

Which operator can be used to create private variables within a subroutine?

  1. native
  2. limited
  3. my
  4. regional
Question 14 Multiple Choice (Single Answer)

Within a loop, which operator jumps to the end of the loop but does not exit the loop?

  1. next
  2. last
  3. redo
  4. leave
Question 15 Multiple Choice (Single Answer)

To convert a timestamp into a format more readable by a user, which function should you use?

  1. bitwise
  2. localtime
  3. translate
  4. transform
Question 16 Multiple Choice (Single Answer)

What value do variables have before they are first assigned?

  1. undef
  2. null
  3. 0
  4. nil
Question 17 Multiple Choice (Single Answer)

Which Perl function is used to change the name of a file?

  1. nameas
  2. rename
  3. name
  4. now_known_as
Question 18 Multiple Choice (Single Answer)

Which of the following commands should be used to open a filehandle named KAREN to an existing file named sw?

  1. open KAREN ">sw";
  2. open KAREN, ">sw";
  3. open "sw" KAREN;
  4. open ">sw", KAREN;
Question 19 Multiple Choice (Single Answer)

Which command should be used to close the filehandle KAREN?

  1. close KAREN "sw";
  2. KAREN close;
  3. close KAREN;
  4. close &KAREN
Question 20 Multiple Choice (Single Answer)

Which function can be used to return such information about a file as its UID, GID, CTIME, etc.?

  1. file
  2. stat
  3. info
  4. mode