Perl Programming Fundamentals

Test your knowledge of Perl programming concepts including variables, loops, arrays, file operations, database connectivity, and system functions.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which file test can be done to see if a file has the sticky bit set on it?

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

Within a loop, which operator immediately ends execution of the loop?

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

You want to close the directory handle EVAN. Which of the following should you use to accomplish this?

  1. close EVAN;
  2. closedir EVAN;
  3. close_directory EVAN;
  4. none of the above
Question 4 Multiple Choice (Single Answer)

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

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

Consider the following program code @array= (“Y”,”W”,”X”); @array=sort(@array); unshift(@array , ”Z”); print($array[0]); What is the output of this code

  1. W
  2. X
  3. Y
  4. Z
Question 6 Multiple Choice (Single Answer)

Consider the following lines of code: @array1 = ("apples", "oranges", "pears", "plums"); foreach (@array1) {print "$_\n"}; What is the result of these lines of code?

  1. applesorangespearsplums
  2. apples oranges pears plums
  3. apples
  4. apples oranges pears plums
Question 7 Multiple Choice (Single Answer)

Which function can be used to print a message to standard error, but not quit the program?

  1. warn
  2. alert
  3. tell
  4. notifiy
Question 8 Multiple Choice (Single Answer)

Suppose the variable $var has the value abc123abc . What is the value of $var after the following substitution?

  1. $var=~ s/(\d+)/ $1*2 /e ;
  2. “abc”
  3. It will produce error
  4. “ABC123ABC”
Question 9 Multiple Choice (Single Answer)

Your script has just read in a variable from the keyboard and you want to strip that variable of the newline character that came in. What operator should you use to perform this operation?

  1. tidy
  2. trim
  3. chomp
  4. slim
Question 10 Multiple Choice (Single Answer)

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

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

Which Perl function can be used to launch a child process to run a program?

  1. split
  2. spin
  3. fork
  4. system
Question 12 Multiple Choice (Single Answer)

Which file test can be done to see if a file exists and has a nonzero size?

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

Within Perl, which operator is used to change the working directory?

  1. cd
  2. chdir
  3. pwd
  4. wd
Question 14 Multiple Choice (Single Answer)

What is the value of @list at the end of the following program? #!/usr/local/bin/perl @list=(1,2.3); &testsub(*list); Sub testsub{ Local (*sublist)=@_; $sublist[1] = 5; }

  1. (1,2.3)
  2. (1,5,3)
  3. Will produce error
  4. (1,4,3)
Question 15 Multiple Choice (Single Answer)

Consider the following program code: @array = (10, Masami, 10..13, Niklas); for ($i = 1; $i < $#array; $i++) { print($array[$i] ); } What is the result of executing this program code?

  1. The code will output the following: Masami 10 11 12 13
  2. The code will output the following: 10 Masami 10 11 12 13
  3. The code will output the following: 10 Masami 11 12 13 Niklas
  4. The code will output the following: Masami 10 11 12 13 Niklas
Question 16 Multiple Choice (Single Answer)

Consider the following program code: $x = 10; LOOP: while ($x < 15) { print ($x ); if ($x >= 14 && $x <= 20) { $x += 2; redo LOOP; } else { $x++; }} What is the result of executing this program code?

  1. The code will output the following: 11 12 13 14 15 16 17 18 19
  2. The code will output the following: 10 11 12 13 14 16 18 20 22
  3. The code will output the following: 10 11 12 13 14 16 18 20
  4. The code will output the following: 10 11 12 13 14 15 16 17 18 19 20
Question 17 Multiple Choice (Single Answer)

Consider the following program code: $y = 1; $x = 2; $z = 3; do { print ($y ); } while ($y eq 2); do { print ($x ); } until ($x eq 2); print ($z ); What is the result of executing this program code?

  1. The code will output the following:123
  2. The code will output the following: 3
  3. The code will output the following:23
  4. The code will output the following: 321
Question 18 Multiple Choice (Single Answer)

Which line of code represents the correct syntax to establish a reference to a database handle?

  1. $dbh = DBI::connect("dbi:mysql:myPhoneBook");
  2. $dbh = DBD:->connect("dbi::mysql::myPhoneBook");
  3. $dbh = DBD::connect("mysql:dbi:myPhoneBook");
  4. $dbh = DBI->connect("dbi:mysql:myPhoneBook");
Question 19 Multiple Choice (Single Answer)

What do the variable $? contains?

  1. Page length of a particular output file
  2. The input end-of-line character
  3. The return code returned by a command called by the system function.
  4. The error code generated by a system library routine.
Question 20 Multiple Choice (Single Answer)

What do the variable $! contains?

  1. Page length of a particular output file
  2. The input end-of-line character
  3. The return code returned by a command called by the system function.
  4. The error code generated by a system library routine.