Perl MCQs

Perl MCQs

Our team has conducted extensive research to compile a set of Perl MCQs. We encourage you to test your Perl knowledge by answering these multiple-choice questions provided below.
Simply scroll down to begin!

1: What is @INC?

A.   it contains all the list of variables defined within the script

B.   It contains unix's environment variables

C.   It contains all the sources of external information

D.   It contains a list of directories from which Perl modules and libraries can be loaded

2: You may call a subroutine called 'subrout' with arguments 'args', using:

A.   subrout args;

B.   &subrout(args);

C.   all are correct

D.   subrout(args);

3: How many scalars will the array @num have after the following command: my @days = qw (Sunday Monday Tuesday Wednesday Thursday Friday Saturday); my @num = (1..scalar @days);

A.   2

B.   0

C.   1

D.   7

4: What does the "shift" function do?

A.   Passes parameters to the subrotuines

B.   Shifts operators bitwise

C.   Removes the first value of an array and returns its value

D.   Swaps array indexes

5: What is the shebang?

A.   %!

B.   $!

C.   &!

D.   #!

E.   @!

6: How would you output the list of keys in a hash?

A.   key %hash

B.   scalar %hash

C.   count %hash

D.   keys %hash

7: Does perl require variables be declared with a type? (ie: int, float, double, etc.)

A.   Yes

B.   No

8: $m=ucfirst("test"); What will be the output of $m?

A.   Test


C.   test

D.   tesT

9: lc function stands for?

A.   last call();

B.   lower case

C.   leastcount

D.   less than

10: You may force yourself to declare your variables by:

A.   using &$variables;

B.   including the 'use strict' pragma in your program

C.   including the 'use autouse' module in your program

D.   using &variables;

11: Which conditional statement is equivalent to "if (!)"?

A.   ifn ()

B.   fails ()

C.   failure ()

D.   unless ()

12: What can be used in PERL for communicating with an FTP server?

A.   FTP

B.   Net::FTP

C.   Net::SMTP


13: To remove any line-ending characters of each string in a @list, you use the function:

A.   remove

B.   trunc

C.   chomp

D.   deleol

14: What is $_ ?

A.   shows current processid

B.   The default input and pattern-searching space.

C.   it display errors

D.   it displays warnings

15: Which of the following gets you an array of all numbers matched in a string?

A.   my @numbers = $string =~ /\S+/g;

B.   my @numbers = $string =~ /\S+/e;

C.   my @numbers = $string =~ /\d+/g;

D.   my @numbers = $string =~ /\W+/e;

16: Unless it is the final statement in a block, every simple statement must end in:

A.   ;

B.   nothing

C.   end of line

D.   .

17: Will perl be installed in Windows by default?

A.   Yes

B.   No

18: Which will check the script's syntax?

A.   perl -check

B.   perl -C

C.   perl -Check

D.   perl -c

19: How can perl be called which gives the same functionality of "use warnings"?

A.   perl -w

B.   perl -warn

C.   perl -Warn

D.   perl -W

20: my $x=join(':','a','b') What will be the output of $x?

A.   b:a

B.   a:b

C.   ba

D.   ab

21: The for loop has few semicolon-separated expressions within its parentheses. These expressions function as:

A.   the initialization (e.g., $i = 1;)

B.   the condition (e.g., $i < 10;)

C.   the re-initialization (e.g., $i++)

D.   all are correct

22: Does Perl provide the defined function that allows you to check up if a variable has the undef value or not?

A.   Yes

B.   No

23: Can a pattern search be done in a split function in PERL?

A.   Yes

B.   No

24: How do you check the existence of a key in a hash?

A.   isused $hash {'key'}

B.   isexists $hash {'key'}

C.   exists $hash {'key'}

D.   isnull $hash {'key'}

25: The prototype symbol for a scalar is:

A.   $

B.   *

C.   %

D.   &

26: What will the following code output? for ($count = 10; $count >= 1; $count--) { print "$count "; }

A.   10 9 8 7 6 5 4 3 2

B.   9 9 8 7 6 5 4 3 2 1

C.   10 9 8 7 6 5 4 3 2 1

D.   9 8 7 6 5 4 3 2 1

27: What are the ways one can run an Unix command?

A.   within backquote

B.   system ()

C.   All of these

28: What will $count= scalar keys %hashname; return?

A.   number of elements in hash

B.   error

C.   executes but blank output

D.   values of only keys in hash

29: What is a hash identified as?

A.   $

B.   @

C.   %

D.   &

30: What will the following program do: foreach (reverse 1..10) { print; }

A.   Syntax error.

B.   Print nothing.

C.   Print the numbers from 10 to 1.

D.   Infinite loop.

E.   Print the numbers from 1 to 10.

31: What does cdup () do in FTP?

A.   shows uptime

B.   Change the directory to the parent of the current directory.

C.   change to any directory in any level

D.   Change directory to the child of the current directory.

32: Perl programs have this filehandle that is automatically opened:





33: Perl has a 'goto' command.

A.   False, the command is 'go'

B.   False, the command is 'branch'

C.   True

34: How can you install a module?

A.   copy the file

B.   cd cpan; install [module name]

C.   cpan; install [module name]

D.   install [module name]

35: What's the preferable mode of executing one CGI script?

A.   755

B.   766

C.   744

D.   776

36: How do I call subroutines in Perl?

A.   sub();

B.   &sub();

C.   All of these

D.   $some_object->sub();

37: Why would I include strict in PERL code?

A.   To hide errors and warnings

B.   When strict is in use and the package name is not used to fully qualify the variable, this error will be reported

C.   To display warnings to the browser

D.   To hide errors

38: Which of the following functions is not used for array processing?

A.   shift

B.   splice

C.   push

D.   chop

39: How do I close a file?

A.   file_close fh

B.   fclose fh

C.   close fh

D.   close $_

40: how would you execute a shell command from within a perl script

A.   use the execute function , ie, execute("ls")

B.   enclose within back ticks , ie `ls`

C.   enclose within #{}, ie, #{ls}

D.   use the escape function , ie escape("ls")

41: Which of the following functions is not used for hash processing?

A.   all are used for hash processing

B.   each

C.   delete

D.   exists

42: How would you remove an element from hash?

A.   delete $hash{'key'}

B.   remove $hash{'key'}

C.   empty $hash{'key'}

D.   $hash{'key'}=''

43: What's is DBI and DBD?

A.   DBI is the common interface to database where DBD is database specific driver

B.   DBI is the interface to Oracle Database and DBD is the Oracle Driver

C.   Both are common pipeline to hetergenous database

D.   DBD is the common interface to database where DBI is database specific driver

44: What does Perl -e on the command line do?

A.   Die on warnings on the program coming after it

B.   Give you the version number

C.   Allow you to execute an expression coming immediately after.

D.   Interpret perl from standard in

45: Which of the below would declare a global variable?

A.   our

B.   /g

C.   my

D.   ~g

46: To execute blocks of code depending on whether a condition is met, you use:

A.   the if statement

B.   the unless statement

C.   both are correct

47: $_ is used by default:

A.   as the default iterator variable in a foreach loop

B.   all are correct

C.   by unary functions like ord and int

D.   by list functions like print and unlink

48: Which of the following is not used for assigning a value to a variable?

A.   &&=

B.   .=

C.   ==

D.   *=

49: To disable a database error, what parameter is set in the database initialization?

A.   raise_error=0

B.   raise_error=255

C.   raise_error=1

D.   raise_error=-1

50: my @b=(1,2,3);my $a=@b;What will be the output of $a?

A.   0

B.   3

C.   2

D.   1