Perl Test

1. What is @INC?
Answers:
• It contains all the sources of external information
• it contains all the list of variables defined within the script
• It contains unix's environment variables
• It contains a list of directories from which Perl modules and libraries can be loaded
2. What function is used to check the length of a string?
Answers:
• using len()
• using count()
• using strlen()
• using length()
3. Why would I include strict in PERL code?
Answers:
• To display warnings to the browser
• When strict is in use and the package name is not used to fully qualify the variable, this error will be reported
• To hide errors and warnings
• To hide errors
4. What does the pop function do?
Answers:
• Add the last value of the array,
• Returns the last value of the array
• Returns the first value of the array
• Add the first value of the array,
5. What's is DBI and DBD?
Answers:
• DBI is the interface to Oracle Database and DBD is the Oracle Driver
• DBD is the common interface to database where DBI is database specific driver
• DBI is the common interface to database where DBD is database specific driver
• Both are common pipeline to hetergenous database
6. How do I call  subroutines in Perl?
Answers:
• $some_object->sub();
• sub();
• &sub();
• All of these
7. Can a pattern search be done in a split function in PERL?
Answers:
• No
• Yes
8. How would you output the list of keys in a hash?
Answers:
• count %hash
• scalar %hash
• key %hash
• keys %hash
9. How do you check the existence of a key in a hash?
Answers:
• isused $hash {'key'}
• isexists $hash {'key'}
• isnull $hash {'key'}
• exists $hash {'key'}
10. The for loop has few semicolon-separated expressions within its parentheses. These expressions function as:
Answers:
• the initialization (e.g., $i = 1;)
• the re-initialization (e.g., $i++)
• the condition (e.g., $i < 10;)
• all are correct
11. Which of the following gets you an array of all numbers matched in a string?
Answers:
• my @numbers = $string =~ /\W+/e;
• my @numbers = $string =~ /\d+/g;
• my @numbers = $string =~ /\S+/g;
• my @numbers = $string =~ /\S+/e;
12. Which will check the script's syntax?
Answers:
• perl -check
• perl -C
• perl -Check
• perl -c
13. What is $_ ?
Answers:
• The default input and pattern-searching space.
• it displays warnings
• it display errors
• shows current processid
14. Which conditional statement is equivalent to "if (!<condition>)"?
Answers:
• failure (<condition>)
• ifn (<condition>)
• fails (<condition>)
• unless (<condition>)
15. my @b=(1,2,3);my $a=scalar(@b);What will be the output of $a?
Answers:
• 3
• 12
• 45
• 1
16. Does perl require variables be declared with a type?  (ie: int, float, double, etc.)
Answers:
• Yes
• No
17. What can be used in PERL for communicating with an FTP server?
Answers:
• Net::SMTP
• WWW::FTP
• FTP
• Net::FTP
18. You may force yourself to declare your variables by:
Answers:
• using &variables;
• using &$variables;
• including the 'use strict' pragma in your program
• including the 'use autouse' module in your program
19. To remove any line-ending characters of each string in a @list, you use the function:
Answers:
• remove
• deleol
• trunc
• chomp
20. $m=ucfirst("test"); What will be the output of $m?
Answers:
• TEST
• tesT
• Test
• test
21. Unless it is the final statement in a block, every simple statement must end in:
Answers:
• end of line
• ;
• nothing
• .
22. lc function stands for?
Answers:
• less than
• leastcount
• lower case
• last call();
23. Will perl be installed in Windows by default?
Answers:
• Yes
• No
24. my $x=join(':','a','b') What will be the output of $x?
Answers:
• a:b
• b:a
• ab
• ba
25. How can perl be called which gives the same functionality of "use warnings"?
Answers:
• perl -Warn
• perl -warn
• perl -W
• perl -w
26. What will the following code output? for ($count = 10; $count >= 1; $count--) {   print "$count ";  }
Answers:
• 9 9 8 7 6 5 4 3 2 1
• 9 8 7 6 5 4 3 2 1
• 10 9 8 7 6 5 4 3 2 1
• 10 9 8 7 6 5 4 3 2
27. The prototype symbol for a scalar is:
Answers:
• *
• &
• %
• $
28. What will   $count= scalar keys %hashname; return?
Answers:
• error
• number of elements in hash
• executes but blank output
• values of only keys in hash
29. What does the "shift" function do?
Answers:
• Removes the first value of an array and returns its value
• Passes parameters to the subrotuines
• Shifts operators bitwise
• Swaps array indexes
30. What are the ways one can run an Unix command?
Answers:
• within backquote
• All of these
• system ()
31. What does cdup () do in FTP?
Answers:
• Change the directory to the parent of the current directory.
• Change directory to the child of the current directory.
• shows uptime
• change to any directory in any level
32. Does Perl provide the defined function that allows you to check up if a variable has the undef value or not?
Answers:
• No
• Yes
33. Perl programs have this filehandle that is automatically opened:
Answers:
• STDDAT
• STDERR
• STDREF
• STDLOG
34. What is the shebang?
Answers:
• @!
• #!
• &!
• $!
• %!
35. What is a hash identified as?
Answers:
• &
• $
• @
• %
36. How can you install a module?
Answers:
• copy the file
• install [module name]
• cpan; install [module name]
• cd cpan; install [module name]
37. Which of the following functions is not used for array processing?
Answers:
• shift
• splice
• chop
• push
38. Perl has a 'goto' command.
Answers:
• False, the command is 'go'
• False, the command is 'branch'
• True
39. What will the following program do: foreach (reverse 1..10) { print; }
Answers:
• Syntax error.
• Print nothing.
• Print the numbers from 10 to 1.
• Infinite loop.
• Print the numbers from 1 to 10.
40. How do I close a file?
Answers:
• file_close fh
• close fh
• close $_
• fclose fh
41. What's the preferable mode of executing one CGI script?
Answers:
• 755
• 776
• 766
• 744
42. 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);
Answers:
• 7
• 0
• 2
• 1
43. how would you execute a shell command from within a perl script
Answers:
• use the escape function , ie escape("ls")
• use the execute function , ie, execute("ls")
• enclose within #{}, ie, #{ls}
• enclose within back ticks , ie `ls`
44. What are the types of variables in PERL?
Answers:
• hash, scalar, var, scalar
• array, hash, scalar
• hash, array, var
• array,var
45. How would you remove an element from hash?
Answers:
• $hash{'key'}=''
• empty $hash{'key'}
• remove $hash{'key'}
• delete $hash{'key'}
46. $_ is used by default:
Answers:
• all are correct
• as the default iterator variable in a foreach loop
• by unary functions like ord and int
• by list functions like print and unlink
47. my @b=(1,2,3);my $a=@b;What will be the output of $a?
Answers:
• 2
• 3
• 1
• 0
48. Using which of the below would declare a global variable?
Answers:
• ~g
• my
• /g
• our
49. What does Perl -e on the command line do?
Answers:
• Give you the version number
• Allow you to execute an expression coming immediately after.
• Die on warnings on the program coming after it
• Interpret perl from standard in
50. what is the default separator in split operator
Answers:
• semi colon
• colon
• white space
• comma
51. To disable a database error,  what parameter is set in the database initialization?
Answers:
• raise_error=-1
• raise_error=0
• raise_error=255
• raise_error=1
52. How do I numericaly sort an array in decending order?
Answers:
• sort ($b cmp $a)
• sort ($a <=> $b)
• sort ($b <=> $a)
53. Which of the following functions is not used for hash processing?
Answers:
• all are used for hash processing
• each
• delete
• exists
54. Which of the following is not used for assigning a value to a variable?
Answers:
• ==
• .=
• *=
• &&=
55. Which one of the following regexes matches between 1 to 4 ab's followed by a tab and an integer number?
Answers:
• ab[ababab]\t[0-9]
• {ab,4}\t\d+
• (ab)+{4}\t\d*
• (ab){1,4}\t\d+
56. How do I lock a file?
Answers:
• using uflock()
• using lock()
• using filelock()
• using flock()
57. To execute blocks of code depending on whether a condition is met, you use:
Answers:
• both are correct
• the if statement
• the unless statement
58. You can create a reference to an existing variable or subroutine by prefixing it with a:
Answers:
• \
• $
• \\
• $$
59. The bitwise AND operator is:
Answers:
• |
• &
• ||
• &&
60. What does append do in FTP?
Answers:
• append to the end of the remote file
• Same as put but uses the STOU command.
• same as put()
• Returns TRUE if the remote server supports the given command.
61. What will be the output of variable $firstVar after completion of this code line: $firstVar = substr("0123BBB789", 4, 3);
Answers:
• 789
• BBB
• B789
• 3BB
62. What must be done to pass more than one array or hash into or out of a function and have them maintain their integrity?
Answers:
• you put them in a list and pass this list
• all answers are wrong
• you pass references to them as arguments
• you put them in an hash (associative array) and pass that
63. Can I call the method of a class without creating an object?
Answers:
• Yes, using Super class object
• by calling new()
• Yes, using :: operator
• No
64. What is closure referencing?
Answers:
• referencing file through hash
• referencing subroutines through variable
• referencing hash through variable
• referencing array through variable
65. our @ISA (person); What does @ISA mean?
Answers:
• current class inherits person class
• create a subclass person
• require person class
• include person module
66. Which regular expression deletes all tags specified as text enclosed by "<" and ">" from a document stored in a string, but deletes nothing else?
Answers:
• $string =~ s/<*&>//g;
• $string =~ s/<.*?>//g;
• $string =~ s/<\s*>//g;
• $string =~ s/<\S*>//g;
67. I can capture output of any unix command through which process?
Answers:
• using execute()
• Using system ()
• using exec () using execute ()
• Using backquote
68. To dereference $arrayref and then find the second element of that array, you use:
Answers:
• $arrayref->[1] = "man";
• all are correct
• ${$arrayref}[1] = "man";
• $$arrayref[1] = "man";
69. What does $! show?
Answers:
• Errors
• Process id
• Warnings
• Perdioda
70. You may call a subroutine called 'subrout' with arguments 'args', using:
Answers:
• all are correct
• subrout(args);
• subrout args;
• &subrout(args);
71. What's the system() success value?
Answers:
• -1
• 255
• 1
• 0
72. How do I dereference a hash reference?
Answers:
• %{%ref}
• ${$ref}
• ${%ref}
• %{$ref}
73. What statement immediately ends a subroutine?
Answers:
• return;
• goto;
• break;
• exit;
74. Which of the following is not used to control scoping?
Answers:
• local
• call
• package
• my
• use
75. What option do I use to check the existence of a file?
Answers:
• "-d"
• "-f"
• "-e"
• "-s"
76. How to create a super class object?
Answers:
• $superclass->new(parameter)
• $class->SUPER::new(parameter)
• $class->[super class name]::new(parameter)
• $class->[super class]->new(parameter)
77. What does unshift do?
Answers:
• Removes an element to the beginning of an array
• Adds an element to the end of an array
• Removes an element to the end of an array
• Adds an element to the beginning of an array
78. Which takes care of garbage collection?
Answers:
• _class name
• remove [class object]
• unlink method
• DESTROY method
79. $@ is associated with the ____ function.
Answers:
• begin block
• eval()
• die()
• main()
80. All arguments to a subroutine are passed as:
Answers:
• distinct scalars
• distinct lists, one per variable
• hashes (associative arrays)
• single, flat list of scalars
81. What does Perl -T do?
Answers:
• timeout parameter
• configuration check
• threaded mode
• use for taint checks
82. What does chop do in PERL?
Answers:
• Removes the last character of a string and returns the removed character
• Removes the last blank space from a string
• Removes the last line feed character from a string
• Removes all new lines from a string
83. What is known as a reference to a function that is, usually, passed into another function for use?
Answers:
• hashreference
• Callback
• dereference
• Closures
84. How can you write content using CGI?
Answers:
• cgiobject->header();cgiobject->start_html(); and cgiobject->end_html();
• cgiobject->header();
• cgiobject->start_html(); and cgiobject->end_html();
• cgiobject->header();cgiobject->write_html();
85. How would you check which version of perl you are using?
Answers:
• perl -version
• None of these
• perl -Verz
• perl -v
86. What would be $x after  my $x = "5" x "4";
Answers:
• 5555
• 20
• Depends on the variable type.
• A value of undef and an error messages.
87. How do I create an object?
Answers:
• class name ( [class parameter] )
• bless [class parameter]
• new [class parameter] [class name]
• bless [class parameter] [class name]
88. What do the @- and @+ arrays do?
Answers:
• Store first and last index of a given array
• Store start and end positions of all regular expression group captures
• Store first and last command line arguments
• Store first and last arguments passed to functions
89. What is the MOST correct answer?
Answers:
• Perl includes the syntax of awk.
• Every awk program can be rewritten in perl, but with a different syntax.
• The use awk functionality one must execute awk from perl using the backward apostrophe `
• To parse a column based text file, awk is better than perl as perl do not support column separation.
90. Perl -I, what is 'l" meant for?
Answers:
• Inplace edit
• Quote filename
• Compile Perl script
91. if $as=="x", then what is the output of the following  print "as".'$as'.$as.""
Answers:
• as$as
• asx$asx
• asasx
• as$asx
92. @values = ( "value1", "value2", ("value3", "value4") ); How does Perl store the nested list shown above?
Answers:
• The list is flattened by removing all internal bracketing.
• The list is stored as a hierarchical list.
• The list is stored as a hash with the offsets as keys to the hash.
• The list stores two values, "value1" and "value2", plus a pointer to the internal list.
93. Which list items of stat() returns the mode of the file?
Answers:
• 3
• 4
• 6
• 5
94. 1 $a="cat"; 2 $$acatches="rat"; Which of following is equivalent to second line.?
Answers:
• acatcatches="rat"
• $catcatches=.rat;
• $catcatches=''rat";
• acatcatches="rat";
95. What module is used to scrape contents from website?
Answers:
• None of these
• Net::LWP
• LWP::Simple
• Data::Dumper
96. What is a correct way to instantiate parallel processing in PERL?
Answers:
• my $pm = new Parallel::ForkManager(50,20);
• my $pm = new ForkManager(50);
• my $pm = new Parallel::ForkManager($$,50);
• my $pm = new Parallel::ForkManager(50);
97. Perl stores numbers internally as:
Answers:
• all are correct
• signed integers
• none are correct
• double-precision floating-point values
98. seek FILEHANDLE, POSITION, OPTION; What's meant by option value as 0 ?
Answers:
• sets position to the end of the file .
• does not make any change
• set new position plus position
• Sets the new position of the file
99. How would I display an error during CGI application?
Answers:
• use CGI::Carp qw(Display Error)
• use CGI::Carp qw(On Error)
• use CGI::Carp qw(fatalsTo Browser)
• use CGI::Carp qw(fatalsToCGI)
100. What does shift(ARRAY) do?
Answers:
• Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything towards the end.
• Shifts the last value of the array off and returns it, shortening the array by 1 and moving everything towards the front.
• Shifts the last value of the array off and returns it, shortening the array by 1 and moving everything towards the end.
• Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything towards the front.
101. Which of the following is a correct use of IMAP?
Answers:
• use Net::IMAP; $server = new Net::IMAP( 'someserver', 'someuser', 'somepassword' );
• use Net::IMAP::Simple; $server = new Net::IMAP::Simple( 'someserver' ); $server->login( 'someuser', 'somepassword' );
• use Net::IMAP::Simple; $server = new Net::IMAP::Simple( 'someserver' ); $server->login( 'someuser', 'somepassword','some port' );
• use Net::IMAP::Simple; $server = new Net::IMAP::Simple( 'someserver' , 'someuser', 'somepassword' );
102. A perl program file name prog.pl starts with the following line: #!/usr/bin/perl -w  The file has execute permissions. What would be the difference between: (a) ./prog.pl (b) perl prog.pl
Answers:
• Command (b) will invoke the program without warnings.
• Second command will not work
• First command will not work
• No difference
103. ?!pattern means regular expression is:
Answers:
• a positive look-behind assertion
• a positive look-ahead assertion
• a negative look-ahead assertion
• a negative look-behind assertion
104. How do I check PERL Module's version?
Answers:
• using $]
• using $$
• using $|
• using $?
105. $b = $a++ + ++$a; What is the value of $b?
Answers:
• 0
• 1
• undef
• 3
• 2
106. What should be the output of @nums = (1..10); splice(@nums, 5,5,21..25)?
Answers:
• 1 2 3 4 5 5 21 22 23 24
• 1 2 3 4 5 21 22 23 24 25 26
• 1 2 3 4 5 21 22 23 24 25
• 1 2 3 4 21 22 23 24 25
107. what is the output of $x="AGAAA"; $x=~tr/AG/C/ds; print $x;
Answers:
• CGCCC
• C
• AAAA
• CCCCC
108. which operator has highest precedence
Answers:
• ++
• +
• *
• ^
109. Which of the following will remove a cookie?
Answers:
• my $cookie1 = new CGI::Cookie( -name=>'Test', -expires=>100, -domain=>"teste.com", -path=>'/', -secure=>0 );
• my $cookie1 = new CGI::Cookie( -name=>'Test', -expires=>1h, -secure=>0 );
• my $cookie1 = new CGI::Cookie( -name=>'Test', -expires=>, -domain=>"teste.com", -path=>'/', -secure=>0 );
• my $cookie1 = new CGI::Cookie( -name=>'Test', -expires=>-1, -domain=>"teste.com", -path=>'/', -secure=>0 );
110. What will be in $test variable? my $test = ( ($a,$b) = (7,7,7,5,45));
Answers:
• 7
• 5
• 45
• 2
• ARRAY(0x1d06760)
111. What is %INC?
Answers:
• It is used to cache the names of the files and the modules that were successfully loaded and compiled by use(), require() or do() statements
• it contains all system objects
• It contains all the inlcuded file's within the script
• It's same as @INC, just stores the information in a hash instead of an array
112. What does +>> signify in file handling?
Answers:
• write/append
• read/write/append
• append
• read/append
113. What is the difference between require and use?
Answers:
• require is verified during compile time and runtime, use is verified during run time
• require is verified during compile time, use is verified during run time
• use is verified during compile time and runtime, require is verified during run time
• require is verified during runtime, use is verified during compile time
114. How can you get the current postion of the file?
Answers:
• tell $_;
• tell FILEHANDLE;
• getpostion tell FILEHANDLE;
• getpos FILEHANDLE;
115. Which of the following expressions allow you to enter the perl debugger without running a program?
Answers:
• perl -d null
• perl -d
• perl -V
• perl -de0
116. How can I  read character by character from a file?
Answers:
• getchar FileHandle
• getc FileHandle
• getchar @_
• getc $_
117. When is begin block evaluated?
Answers:
• at the beginning of any script
• it's evaluated as it's being called
• as soon as it is defined
• at the end
118. How do I handle transaction control in PERL?
Answers:
• Set Autocommit=0;use commit and rollback
• Set Autocommit=1;use BEGIN TRANSACTION and END TRANSACTION
• Set Autocommit=0;use BEGIN TRANSACTION and END TRANSACTION
• Set Autocommit=1;use commit and rollback
119. What does $1 hold? $x= "a walk in the park";$x=~/(.+)a/;
Answers:
• a walk in the p
• a w
• empty string
120. For the string "2011/12/04" and regular expression "/(\d+)\/(\d+)\/(\d+)/", you can use $3 to return "04".  What other variable can be used to return "04"?
Answers:
• $'
• $+
• $&
• $`
• $^
121. What  does die() do?
Answers:
• Exits the process
• Sets error code as 0
• Set the error code based on $! or $? if the exception is uncaught
• It does not throw any exceptions
122. Which one of the following completely defines scalars?
Answers:
• A pointer, a stack, or a heap
• An int, float, double, or char
• A single string, number, or reference
• A string, a lexical array, or a numeric value

No comments:

Post a Comment