Elance Perl Test Answers 2015



What is @INC?
it contains all the list of variables defined within the script
It contains a list of directories from which Perl modules and libraries can be loaded
It contains all the sources of external information
It contains unix's environment variables


You can create a reference to an existing variable or subroutine by prefixing it with a:
\
$$
$
\\


All arguments to a subroutine are passed as:
distinct lists, one per variable
hashes (associative arrays)
distinct scalars
single, flat list of scalars


The bitwise AND operator is:
|
&
||
&&


Which one of the following regexes matches between 1 to 4 ab's followed by a tab and an integer number?
(ab){1,4}\t\d+
{ab,4}\t\d+
ab[ababab]\t[0-9]
(ab)+{4}\t\d*


What will be the output of variable $firstVar after completion of this code line: $firstVar = substr("0123BBB789", 4, 3);
B789
3BB
789
BBB


To execute blocks of code depending on whether a condition is met, you use:
both are correct
the if statement
the unless statement


Can I call the method of a class without creating an object?
Yes, using Super class object
by calling new()
No
Yes, using :: operator


Which of the following is not used for assigning a value to a variable?
*=
&&=
==
.=


$_ is used by default:
by unary functions like ord and int
as the default iterator variable in a foreach loop
by list functions like print and unlink
all are correct


What does Perl -e on the command line do?
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


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);
1
7
2
0


Why would I include strict in PERL code?
To hide errors
When strict is in use and the package name is not used to fully qualify the variable, this error will be reported
To display warnings to the browser
To hide errors and warnings


What are the types of variables in PERL?
array,var
array, hash, scalar
hash, array, var
hash, scalar, var, scalar


how would you execute a shell command from within a perl script
use the execute function , ie, execute("ls")
use the escape function , ie escape("ls")
enclose within #{}, ie, #{ls}
enclose within back ticks , ie `ls`


What's the preferable mode of executing one CGI script?
755
776
744
766


Which of the following functions is not used for array processing?
chop
push
shift
splice


How do I call subroutines in Perl?
sub();
All of these
&sub();
$some_object->sub();


What's is DBI and DBD?
Both are common pipeline to hetergenous database
DBI is the common interface to database where DBD is database specific driver
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


How do I close a file?
fclose fh
close $_
close fh
file_close fh


What is the shebang?
@!
&!
$!
#!
%!


How can you install a module?
copy the file
install [module name]
cpan; install [module name]
cd cpan; install [module name]


Perl programs have this filehandle that is automatically opened:
STDREF
STDLOG
STDERR
STDDAT


What will the following program do: foreach (reverse 1..10) { print; }
Print nothing.
Infinite loop.
Print the numbers from 1 to 10.
Print the numbers from 10 to 1.
Syntax error.


How would you output the list of keys in a hash?
count %hash
keys %hash
key %hash
scalar %hash


The prototype symbol for a scalar is:
*
%
&
$


What does the "shift" function do?
Passes parameters to the subrotuines
Swaps array indexes
Removes the first value of an array and returns its value
Shifts operators bitwise


How do you check the existence of a key in a hash?
isnull $hash {'key'}
isexists $hash {'key'}
isused $hash {'key'}
exists $hash {'key'}


The for loop has few semicolon-separated expressions within its parentheses. These expressions function as:
the re-initialization (e.g., $i++)
all are correct
the condition (e.g., $i < 10;)
the initialization (e.g., $i = 1;)


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


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


Can a pattern search be done in a split function in PERL?
No
Yes


What will the following code output? for ($count = 10; $count >= 1; $count--) { print "$count "; }
9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2
10 9 8 7 6 5 4 3 2 1
9 9 8 7 6 5 4 3 2 1


What will $count= scalar keys %hashname; return?
number of elements in hash
values of only keys in hash
executes but blank output
error


What are the ways one can run an Unix command?
within backquote
system ()
All of these


What is a hash identified as?
@
$
&
%


Which conditional statement is equivalent to "if (!<condition>)"?
failure (<condition>)
ifn (<condition>)
fails (<condition>)
unless (<condition>)


Which will check the script's syntax?
perl -Check
perl -check
perl -C
perl -c


Which of the following gets you an array of all numbers matched in a string?
my @numbers = $string =~ /\W+/e;
my @numbers = $string =~ /\d+/g;
my @numbers = $string =~ /\S+/e;
my @numbers = $string =~ /\S+/g;


What can be used in PERL for communicating with an FTP server?
Net::SMTP
WWW::FTP
FTP
Net::FTP


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


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


What is $_ ?
shows current processid
it displays warnings
The default input and pattern-searching space.
it display errors


$m=ucfirst("test"); What will be the output of $m?
test
TEST
tesT
Test


You may force yourself to declare your variables by:
including the 'use strict' pragma in your program
including the 'use autouse' module in your program
using &$variables;
using &variables;


Will perl be installed in Windows by default?
No
Yes


lc function stands for?
less than
lower case
leastcount
last call();


Unless it is the final statement in a block, every simple statement must end in:
.
;
nothing
end of line


How can perl be called which gives the same functionality of "use warnings"?
perl -W
perl -w
perl -Warn
perl -warn


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


What does cdup () do in FTP?
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


Perl has a 'goto' command.
False, the command is 'go'
False, the command is 'branch'
True


How would you remove an element from hash?
delete $hash{'key'}
empty $hash{'key'}
$hash{'key'}=''
remove $hash{'key'}


Which of the following functions is not used for hash processing?
delete
exists
all are used for hash processing
each


Using which of the below would declare a global variable?
our
/g
~g
my


To disable a database error, what parameter is set in the database initialization?
raise_error=1
raise_error=0
raise_error=-1
raise_error=255


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


what is the default separator in split operator
semi colon
white space
comma
colon


How do I numericaly sort an array in decending order?
sort ($b cmp $a)
sort ($b <=> $a)
sort ($a <=> $b)


How do I lock a file?
using filelock()
using flock()
using lock()
using uflock()


What must be done to pass more than one array or hash into or out of a function and have them maintain their integrity?
all answers are wrong
you put them in an hash (associative array) and pass that
you pass references to them as arguments
you put them in a list and pass this list


What statement immediately ends a subroutine?
goto;
break;
exit;
return;


You may call a subroutine called 'subrout' with arguments 'args', using:
all are correct
subrout args;
&subrout(args);
subrout(args);


our @ISA (person); What does @ISA mean?
create a subclass person
require person class
include person module
current class inherits person class


What is closure referencing?
referencing hash through variable
referencing array through variable
referencing subroutines through variable
referencing file through hash


What's the system() success value?
-1
255
0
1


What does $! show?
Process id
Errors
Perdioda
Warnings


Which regular expression deletes all tags specified as text enclosed by "<" and ">" from a document stored in a string, but deletes nothing else?
$string =~ s/<.*?>//g;
$string =~ s/<*&>//g;
$string =~ s/<\S*>//g;
$string =~ s/<\s*>//g;


What function is used to check the length of a string?
using strlen()
using count()
using len()
using length()


How would you check which version of perl you are using?
perl -version
perl -Verz
perl -v
None of these


I can capture output of any unix command through which process?
using execute()
using exec () using execute ()
Using backquote
Using system ()


What does append do in FTP?
same as put()
Returns TRUE if the remote server supports the given command.
Same as put but uses the STOU command.
append to the end of the remote file


What option do I use to check the existence of a file?
"-s"
"-f"
"-d"
"-e"


How do I dereference a hash reference?
%{$ref}
${%ref}
${$ref}
%{%ref}


To dereference $arrayref and then find the second element of that array, you use:
$$arrayref[1] = "man";
${$arrayref}[1] = "man";
all are correct
$arrayref->[1] = "man";


Which of the following is not used to control scoping?
call
package
local
my
use


What does unshift do?
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


Which takes care of garbage collection?
unlink method
remove [class object]
DESTROY method
_class name


What does Perl -T do?
use for taint checks
threaded mode
timeout parameter
configuration check


How to create a super class object?
$class->SUPER::new(parameter)
$class->[super class]->new(parameter)
$class->[super class name]::new(parameter)
$superclass->new(parameter)


$@ is associated with the ____ function.
eval()
begin block
die()
main()


What does chop do in PERL?
Removes the last character of a string and returns the removed character
Removes the last line feed character from a string
Removes all new lines from a string
Removes the last blank space from a string


What is known as a reference to a function that is, usually, passed into another function for use?
hashreference
Closures
dereference
Callback


How can you write content using CGI?
cgiobject->start_html(); and cgiobject->end_html();
cgiobject->header();
cgiobject->header();cgiobject->start_html(); and cgiobject->end_html();
cgiobject->header();cgiobject->write_html();


What would be $x after my $x = "5" x "4";
A value of undef and an error messages.
20
Depends on the variable type.
5555


What do the @- and @+ arrays do?
Store first and last index of a given array
Store first and last command line arguments
Store start and end positions of all regular expression group captures
Store first and last arguments passed to functions


Perl -I, what is 'l" meant for?
Compile Perl script
Quote filename
Inplace edit


What will be the @arr value after executing: my @arr = grep { $_ > 0 } map { $_ * $_ } (1, -1, 2, -2);
@arr = (1, 2)
@arr = (1, 4, 1, 4)
@arr = (1, 1, 4, 4)
@arr = (1, 4)


How do I create an object?
class name ( [class parameter] )
bless [class parameter]
bless [class parameter] [class name]
new [class parameter] [class name]


What module is used to scrape contents from website?
Net::LWP
None of these
Data::Dumper
LWP::Simple


What is the MOST correct answer?
The use awk functionality one must execute awk from perl using the backward apostrophe `
Every awk program can be rewritten in perl, but with a different syntax.
To parse a column based text file, awk is better than perl as perl do not support column separation.
Perl includes the syntax of awk.


@values = ( "value1", "value2", ("value3", "value4") ); How does Perl store the nested list shown above?
The list stores two values, "value1" and "value2", plus a pointer to the internal list.
The list is stored as a hash with the offsets as keys to the hash.
The list is flattened by removing all internal bracketing.
The list is stored as a hierarchical list.


if $as=="x", then what is the output of the following print "as".'$as'.$as.""
asasx
as$asx
as$as
asx$asx


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
Second command will not work
Command (b) will invoke the program without warnings.
No difference
First command will not work


1 $a="cat"; 2 $$acatches="rat"; Which of following is equivalent to second line.?
acatcatches="rat"
$catcatches=''rat";
acatcatches="rat";
$catcatches=.rat;


How would I display an error during CGI application?
use CGI::Carp qw(Display Error)
use CGI::Carp qw(fatalsTo Browser)
use CGI::Carp qw(fatalsToCGI)
use CGI::Carp qw(On Error)


Which list items of stat() returns the mode of the file?
3
4
6
5


?!pattern means regular expression is:
a positive look-ahead assertion
a negative look-behind assertion
a positive look-behind assertion
a negative look-ahead assertion


Perl stores numbers internally as:
all are correct
signed integers
double-precision floating-point values
none are correct


What should be the output of @nums = (1..10); splice(@nums, 5,5,21..25)?
1 2 3 4 5 21 22 23 24 25 26
1 2 3 4 5 5 21 22 23 24
1 2 3 4 21 22 23 24 25
1 2 3 4 5 21 22 23 24 25


What is a correct way to instantiate parallel processing in PERL?
my $pm = new Parallel::ForkManager(50,20);
my $pm = new ForkManager(50);
my $pm = new Parallel::ForkManager(50);
my $pm = new Parallel::ForkManager($$,50);


seek FILEHANDLE, POSITION, OPTION; What's meant by option value as 0 ?
Sets the new position of the file
does not make any change
sets position to the end of the file .
set new position plus position


How do I check PERL Module's version?
using $$
using $]
using $|
using $?


What is %INC?
It's same as @INC, just stores the information in a hash instead of an array
it contains all system objects
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 the inlcuded file's within the script


Which of the following is a correct use of IMAP?
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' ); $server->login( 'someuser', 'somepassword' );
use Net::IMAP; $server = new Net::IMAP( 'someserver', 'someuser', 'somepassword' );
use Net::IMAP::Simple; $server = new Net::IMAP::Simple( 'someserver' , 'someuser', 'somepassword' );


which operator has highest precedence
*
++
^
+


what is the output of $x="AGAAA"; $x=~tr/AG/C/ds; print $x;
CGCCC
C
AAAA
CCCCC


What is the difference between require and use?
require is verified during runtime, use is verified during compile 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 compile time and runtime, use is verified during run time


Which of the following will remove a cookie?
my $cookie1 = new CGI::Cookie( -name=>'Test', -expires=>, -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=>100, -domain=>"teste.com", -path=>'/', -secure=>0 );
my $cookie1 = new CGI::Cookie( -name=>'Test', -expires=>-1, -domain=>"teste.com", -path=>'/', -secure=>0 );


$b = $a++ + ++$a; What is the value of $b?
2
0
3
1
undef


How can you get the current postion of the file?
getpostion tell FILEHANDLE;
tell $_;
tell FILEHANDLE;
getpos FILEHANDLE;


How can I read character by character from a file?
getchar FileHandle
getc FileHandle
getchar @_
getc $_


What does +>> signify in file handling?
read/append
write/append
append
read/write/append


Which of the following expressions allow you to enter the perl debugger without running a program?
perl -d
perl -V
perl -d null
perl -de0


What will be in $test variable? my $test = ( ($a,$b) = (7,7,7,5,45));
ARRAY(0x1d06760)
45
5
2
7


When is begin block evaluated?
at the beginning of any script
at the end
it's evaluated as it's being called
as soon as it is defined


How do I handle transaction control in PERL?
Set Autocommit=1;use BEGIN TRANSACTION and END TRANSACTION
Set Autocommit=1;use commit and rollback
Set Autocommit=0;use BEGIN TRANSACTION and END TRANSACTION
Set Autocommit=0;use commit and rollback


What does $1 hold? $x= "a walk in the park";$x=~/(.+)a/;
a w
empty string
a walk in the p


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"?
$^
$'
$+
$&
$`


What does die() do?
Exits the process
It does not throw any exceptions
Set the error code based on $! or $? if the exception is uncaught
Sets error code as 0

No comments:

Post a Comment