300+[LATEST] Perl Scripting Interview Questions and Answers

Q1. What Is Obp And How Do You Access It?

OBP is called as Open Boot PROM. This OBP can be accessiable thru ok> prompt

Q2. Write A Script To Reverse A String Without Using Perl’s Built In Functions?

my $txt = ‘Hello World’;
my $len= length($txt);
my $rev;
while($len > 0){
$len–;
$rev .= substr($txt,$len,1);
}
print $txt, ‘ – Reversed = ‘ , $rev;

Q3. Which Of These Is A Difference Between C++ And Perl?

Perl can have objects whose data cannot be accessed outside its class, but C++ cannot.
Perl can use closures with unreachable private data as objects, and C++ doesn’t support closures. Furthermore, C++ does support pointer arithmetic via `int *ip = (int*)&object’, allowing you do look all over the object. Perl doesn’t have pointer arithmetic. It also doesn’t allow `#define private public’ to change access rights to foreign objects. On the other hand, once you start poking around in /dev/mem, no one is safe.

Q4. What Is Hash?

Hash is an associative array where data is stored in
“key”->”value” pairs.
Eg : fruits is a hash having their names and price
%fruits = (“Apple”, “60”, “Banana”, “20”, “Peers”, “40”);

Q5. Is There Any Way To Add Two Arrays Together?

Of course you can add two arrays together by using push function. The push function adds a value or values to the end of an array. The push function pushes the values of list onto the end of the array. Length of an array can be increased by the length of list.

Q6. What Are Scalar Data And Scalar Variables?

Perl has a flexible concept of data types. Scalar me a single thing, like a number or string. So the Java concept of int, float, double and string equals to Perl’s scalar in concept and the numbers and strings are exchangeable. Scalar variable is a Perl variable that is used to store scalar data. It uses a dollar sign $ and followed by one or more aphanumeric characters or underscores. It is case sensitive.

Q7. How To Concatinate Strings In Perl?

through . operator

Q8. Advantages Of C Over Perl?

In reality PERL interpreter is written in C. So what all advantages C have are also possesed by PERL. Otherwise C is faster than PERL, because PERL is an interpreted language.

Q9. What Is A Regular Expression?

it defines a pattern for a search to match.

Q10. How To Connect With Sqlserver From Perl And How To Display Database Table Info?

There is a module in perl named DBI – Database independent interface which will be used to connect to any database by using same code. Along with DBI we should use database specific module here it is SQL server. for MSaccess it is DBD::ODBC, for MySQL it is DBD::mysql driver, for integrating oracle with perl use DBD::oracle driver is used. IIy for SQL server there are available many custom defined ppm( perl package manager) like Win32::ODBC, mssql::oleDB etc.so, together with DBI, mssql::oleDB we can access SQL server database from perl. The commands to access database is same for any database.

Q11. How To Code In Perl To Implement The Tail Function In Unix?

You have to maintain a structure to store the line number and the size of the file at that time eg. 1-10bytes, 2-18bytes.. you have a counter to increase the number of lines to find out the number of lines in the file. once you are through the file, you will know the size of the file at any nth line, use ‘sysseek’ to move the file pointer back to that position (last 10) and then start reading till the end.

Q12. How Do You Open A File For Writing?

open FILEHANDLE, “>$FILENAME”

Q13. What Is The Tk Module?

it provides a GUI interface.

Q14. What Does This Mean :
‘$_’ ?

Default variable in Perl.
Its an Default variable in Perl, where the input from the user will be taken into this variable if the variable is not defined by the user.

Q15. What Does Init 5 And Init 0 Do?

init 5 will shutdown and Power-off the server.

init 0 will bring the server to the ok> prompt (Fourth monitor)

Q16. What Is Perl?

Perl is a programming language which is based on shell, C, Lisp, etc. In general, Perl is mainly used for network operations, OS program and for developing some websites.

Q17. How Do You Boot From Cd-rom?

Booting form CD-ROM can be done by the command
ok >boot cdrom

Q18. What Is Cpan ? What Are The Modules Coming Under This?

CPAN is Comprehensive Perl Archive Network. It’s a repository contains thousands of Perl modules, source and documentation, and all under GNU/GPL or similar license. Some Linux distributions provide a tool named “cpan” with which you can install packages directly from CPAN

Q19. What Is Vts?

Sun Validation Test Suite -> tests and validates Sun hardware by verifying the configuration and functionality of hardware controllers, devices

Q20. What Package You Use To Create A Windows Services?

use Win32::OLE.

Q21. Why To Use Perl Scripting?

Perl scripting is mainly used in functional concepts as well as regular expressions, you can also design own policies to obtain generalized pattern using regular expression. Perl is compatible or supports more than 76 operating systems and 3000 modules and it is known as Comprehensive Perl Archive Network modules.

Q22. What Value Is Returned By A Lone Return; Statement?

The undefined value in scalar context, and the empty list value () in list context. This way functions that wish to return failure can just use a simple return without worrying about the context in which they were called.

Q23. What Is Grep Used For In Perl?

Grep is used with regular expression to check if a parituclar value exist in an array. it returns 0 if the value does not exists, 1 otherwise.

Q24. Distinguish My And Local?

The variables which are declared using “my” lives only in that particular block ion which they are declared and inherited functions do not have a visibility that are called in that block. The variables which are defined as “local” are visible in that block and they have a visibility in functions which are called in that particular block.

Q25. Can You Add Two Arrays Together?

Yes, it is possible to add two arrays together with a push function. A value or values to end of the array is added using push function. The values of list are pushed on to the end of an array using push function. Length of list is used to increase length of an array.

Q26. Why To Use Perl?

• It is a powerful interpreter for free.
• Perl is flexible and portable. It is very easy to learn Perl language.

Q27. What Is Perl Scripting?

Perl Scripting is one of the robust scripting languages in the IT market which is being used in “n” of fields. Perl is rich in finding Regular expressions and stands unique in all fields of application.

PERL is a scripting language. Since all scripting languages are interpreter based languages but not compiler based languages, we use for optimization of code in all application.

Q28. How To Create A Package?

pkgmk -o -r / -d /tmp -f Prototype

Q29. What Does This Symbol Mean ‘->’?

In Perl it is an infix dereference operator. for array subscript, or a hash key, or a subroutine, then this must be a reference. can also be used as method invocation.

Q30. How We Can Navigate The Xml Documents?

You can use SAX if what you require is simple accesing of the xml structure. You can go for DOM if you need node handling capabilities like inserting a node, modifying a node, deleteing node and stuff like that.

Q31. What Is Meant By Splicing Arrays Explain In Context Of List And Scalar.

Splicing an array me adding elements from a list to that array, possibly replacing elements now in the array. In list context, the splice function returns the elements removed from the array. In scalar context, the splice function returns the last element removed.

Q32. What Does Perl Do If You Try To Exploit The Execve(2) Race Involving Setuid Scripts?

Sends mail to root and exits. It has been said that all programs advance to the point of being able to automatically read mail. While not quite at that point (well, without having a module loaded), Perl does at least automatically send it.

Q33. Which Has Highest Precedence In Between List And Terms? Explain?

In Perl, the highest precedence is for Perl. Quotes, variables, expressions in parenthesis are included in the Terms. The same level of precedence as Terms is for List operators. Especially, these operators have strong left word precedence.

Q34. How To Start Perl In Interactive Mode?

perl -e -d 1 PerlConsole.

Q35. Differentiate Use And Require?

Use:

  • This method is used for modules.
  • The objects which are included are varied at compilation time.
  • You need not give a file extension.

Require:

  • This method is used for both modules and libraries.
  • The objects are included are verified at run time.
  • You need not give file extension.

Q36. What Is It Meants By ‘$_’?

it is a default variable which holds automatically, a list of arguements passed to the subroutine within parenthesis.

Q37. Why -w Argument Is Used With Perl Programs?

-w option of the interpreter is used by most of the Perl developers especially in the development stage of an application. It is warning option to turn on multiple warning messages that are useful in understanding and debugging the application.

Q38. Perl Regular Expressions Are Greedy” What Does This Mean?

Perl regular expressions normally match the longest string possible. that is what is called as “greedy match”

Q39. How Do You Connect To Database In Perl

There is DBI module. use DBI;my $dbh = DBI->connect(‘dbi:Oracle:orcl’, ‘username’, ‘password’,)where username and password is yours. This is example for oracle database.

For Sybase:
use DBI;
my $dbh = DBI->connect(‘dbi:Sybase:server=$SERVER’, ‘username’, ‘password’)

Q40. What Is The Use Of “stderr()”?

STDERR:
The special filehandle for standard error in any package.

Q41. What Is The Difference Between Exec And System?

exec runs the given process, switches to its name and never returns while system forks off the given process, waits for its to complete and then return.

Q42. Define Perl Scripting?

In the IT market, Perl scripting is considered as a robust scripting language which is used in various fields. Perl is good at obtaining Regular expressions and in all the fields of application it is unique. Perl is a scripting language which is based on interpreter but not on the languages based on compiler. In all the applications, optimization is used.

Q43. Help In Perl?

perldoc -f print

Q44. How To Concatenate Strings With Perl?

Method #1 – using Perl’s dot operator:
$name = ‘checkbook’;
$filename = “/tmp/” . $name . “.tmp”;

Method #2 – using Perl’s join function
$name = “checkbook”;
$filename = join “”, “/tmp/”, $name, “.tmp”;

Method #3 – usual way of concatenating strings
$filename = “/tmp/${name}.tmp”;

Q45. What Does Ndd Do?

ndd command will hardcore the speed of the network interface card.

Q46. List The Files In Current Directory Sorted By Size ?

– ls -l | grep ^- | sort -nr

Q47. How Do Find The Length Of An Array?

$@array

Q48. What Are The Different Types Of Perl Operators?

There are four different types of perl operators they are
(i) Unary operator like the not operator
(ii) Binary operator like the addition operator
(iii) Tertiary operator like the conditional operator
(iv) List operator like the print operator

Q49. How Do You View Shared Memory Statistics?

swap -l -> displays swap usage
prstat -> examines all active processes on the system and reports statistics based
on the selected output mode and sort order
vmstat -> reports information about processes, memory, paging, block IO, traps,
and cpu activity
pmap -> lists the virtual memory mappings underlying the given process

Q50. What Are The Arguements We Normally Use For Perl Interpreter

-e for Execute, -c to compile, -d to call the debugger on the file specified, -T for traint mode for security/input checking -W for show all warning mode (or -w to show less warning)