December 29, 2017

Srikaanth Kumar

Perl Scripting Latest Interview Questions Answers

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.

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.

Why Perl Patterns Are Not Regular Expressions?

Perl patterns have back references
By the definition, a regular expression should determine next state infinite automation without extra money to keep in previous state. State machine is required by the pattern / ([ab] +) c1/ to remember old states. Such patterns are disqualified as being regular expressions in the term’s classic sense.

What Happens If A Reference Is Returned To Private Variable?

Your variables are kept on track by the Perl, whether dynamic or else, and does not free things before you use them.

What Are Scalar Data And Scalar Variables?

Perl has a flexible concept of data types. Scalar means 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.

How To Start Perl In Interactive Mode?

perl -e -d 1 PerlConsole.

What Package You Use To Create A Windows Services?

use Win32::OLE.

What Is A Datahash()
in Win32::ODBC, DataHash() function is used to get the data fetched through the sql statement in a hash format.

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.

What Is Cpan?

CPAN is comprehensive Perl Archive Network. its a repository contains thousands of Perl Modules, source and documentation, and all under GNU/GPL or smilar licence. Some linux distribution provide a till names 'cpan'; which you can install packages directly from cpan.

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.

What Is The Difference Between For And Foreach?

functionally, there is no difference between them.

What Is A Regular Expression?

it defines a pattern for a search to match.

What Is Stderr() In Perl?

special file handler to standard error in any package.

List The Files In Current Directory Sorted By Size ?

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

Define Scalar Data And Variables?

The concept of data types is flexible, which is present in Perl. Scalar is a single thing such as a string or a number. The java concepts such as int, float, string, and double are similar to scalar concept of Perl. Strings and numbers are exchangeable. Scalar variable is nothing but a Perl variable which is used to store scalar data. A dollar sign $ is used by it which is followed by underscores or alphanumeric characters. It is a case sensitive.

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.

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.

Define A Short Circuit Operator?

The C-style operator ll carries out logical operation which is used to tie logical clauses, overall value of true is returned if either clause is true. This operator is known as short-circuit operator because you need not check or evaluate right operand if the left operand is true.

In Perl, Name Different Forms Of Goto And Explain?

In Perl, there are three different forms for goto, they are:

goto name

goto label

goto expr

goto name is used along with subroutines, it is used only when it is required as it creates destruction in programs. It is the second form of label where Execution is transferred to a statement labeled LABEL using goto LABEL. The last label form is goto EXPR which expects EXPR to evaluate label.

Describe Returning Values From Subroutines?

The value of last expression which is evaluated is the return value of subroutine or explicitly, a returned statement can be used to exit subroutine which specifies return value. This return value is evaluated in perfect content based on content of subroutine call.

What Are The Two Different Types Of Data Perl Handles?

Perl handles two types of data they are

(i) Scalar Variables and

(ii) Lists

Scalar variables hold a single data item whereas lists hold multiple data items.

What Are Scalar Variables?

Scalar variables are what many programming languages refer to as simple variables. They hold a single data item, a number, a string, or a perl reference. Scalars are called scalars to differentiate them from constructs that can hold more than one item, like arrays.

Explain About Lists?

A list is a construct that associates data elements together and you can specify a list by enclosing those elements in parenthesis and separating them with commas. They could themselves be arrays, hashes or even other lists. Lists do not have a specific list data type.

Name All The Prefix Dereferencer In Perl?

The symbol that starts all scalar variables is called a prefix dereferencer. The different types of dereferencer are.

(i) $-Scalar variables

(ii) %-Hash variables

(iii) @-arrays

(iv) &-subroutines

(v) Type globs-*myvar stands for @myvar, %myvar.

Explain About An Ivalue?

An ivalue is an item that can serve as the target of an assignment. The term I value originally meant a “left value”, which is to say a value that appears on the left. An ivalue usually represents a data space in memory and you can store data using the ivalues name. Any variable can serve as an ivalue.

How Does A "grep" Function Perform?

Grep returns the number of lines the expression is true. Grep returns a sub list of a list for which a specific criterion is true. This function often involves pattern matching. It modifies the elements in the original list.

Explain About Typeglobs?

Type globs are another integral type in perl. A typeglob`s prefix derefrencer is *, which is also the wild card character because you can use typeglobs to create an alias for all types associated with a particular name. All kinds of manipulations are possible with typeglobs.

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.

How To Use The Command Shift?

Shift array function shifts off the first value of the array and returns it, thereby shortening the array by one element and moving everything from one place to the left. If you don’t specify an array to shift, shift uses @ ARGV, the array of command line arguments passed to the script or the array named @-.

What Exactly Is Grooving And Shortening Of The Array?

You can change the number of elements in an array simply by changing the value of the last index of/in the array $#array. In fact, if you simply refer to a nonexistent element in an array perl extends the array as needed, creating new elements. It also includes new elements in its array.

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.

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.

Why To Use Perl?

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

Why Do You Create An Application For Real Time System In Which Processing Speed Is Vital?

Perl is used in the following cases:

To process large text
When data manipulation is done by application
If you require fast developments expand to become libraries
To load database operations

Which Is Your Favorite Module And Why It Is? is my favorite module and it handles several tasks such as printing the headers, parsing the form input and it handles sessions and cookies effectively.

How Perl Warnings Are Turn On And Why Is It Important?

In general, Perl excuse strange and also wrong code sometimes. Thus, the time spent for searching weird results and bugs in very high. You can identify common mistakes and strange places in the code easily when warnings are turned on. In the long run, the time required for debugging is saved a lot.

There are numerous ways to turn on the warnings of Perl:

-w option is used on the command line for Perl one-liner
-w option on shebang line is used on windows or UNIX. Windows Perl interpreter do not require it.
For other systems, compiler documentation is checked or compiler warnings are selected.

Differentiate Use And Require?


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


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

What Is Meant 'die' In A Perl Program?

If the condition defined before the DIE statement is NOT met, the script will stop execution at that point, printing out the default error, if a custom error message is not defined.

What Is Hash In Perl?

Hash in basically used to comment the script line.
A hash is and unordered set of key/value pairs that you access using strings (keys) as subscripts, to look up the scalar value corresponding to a given key.

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.

What Is A Datahash(). What Does It Mean? And For What Purpose It Is Used??

In Win32::ODBC, DataHash() function is used to get the data fetched through the sql statement in a hash format.

Explain About Returning Values From Subroutines (functions)?

The return value of the subroutine is the value of the last expression evaluated or you can explicitly use a return statement to exit the subroutine specifying the return value. That return value is evaluated in the appropriate content depending on the content of the subroutine call.

What Is Meant By A 'pack' In Perl?

Pack Converts a list into a binary representation
Takes an array or list of values and packs it into a binary structure, returning the string containing the structure
Hope that kills the problem
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')

What Is A Short Circuit Operator?

The C-Style operator, ll, performs a logical (or) operation and you can use it to tie logical clauses together, returning an overall value of true if either clause is true. This operator is called a short-circuit operator because if the left operand is true the right operand is not checked or evaluated.

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, together with DBI, mssql::oleDB we can access SQL server database from perl. The commands to access database is same for any database.

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.

How To Turn On Perl Warnings? Why Is That Important?

Perl is very forgiving of strange and sometimes wrong code, which can mean hours spent searching for bugs and weird results. Turning on warnings helps uncover common mistakes and strange places and save a lot of debugging time in the long run. There are various ways of turning on Perlwarnings:

For Perl one-liner, use -w option on the command line.

On Unix or Windows, use the -w option in the shebang line (The first # line in the script). Note: Windows Perl interpreter may not require it.

For other systems, choose compiler warnings, or check compiler documentation.

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){
$rev .= substr($txt,$len,1);
print $txt, ' - Reversed = ' , $rev;

What Is Perl One-liner?

There are two ways a Perl script can be run:

--from a command line, called one-liner, that means you type and execute immediately on the command line. You'll need the -e option to start like "C: %gt perl -e "print "Hello";". One-liner doesn't mean one Perl statement. One-liner may contain many statements in one line.
--from a script file, called Perl program.

What Are The Different Types Of Eval Statements?

There are two different types of eval statements they are eval EXPR and eval BLOCK.
Eval EXPR executes an expression and eval BLOCK executes BLOCK. Eval Block executes an entire block, BLOCK. First one is used when you want your code passed in the expression and the second one is used to parse the code in the block.

What Is Your Experience Of Interfacing Perl To Database?

The correct answer is DBI

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

Given A File, Count The Word Occurrence (case Insensitive)?

@array=; $wor="word to be found";
$count=0; foreach $line (@array) { @arr=split (/s+/,$line);
foreach $word (@arr) { if ($word =~ /s*$wors*/i) $count=$count+1; } }

print "The word occurs $count times";

How Do I Set Environment Variables In Perl Programs?

As you may remember, "%ENV" is a special hash in Perl that contains the value of all your environment variables.

Because %ENV is a hash, you can set environment variables just as you'd set the value of any Perl hash variable. Here's how you can set your PATH variable to make sure the following four directories are in your path::

$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/home/yourname/bin';

Why We Use Perl?

1.Perl is a powerful free interpreter.

2.Perl is portable, flexible and easy to learn.

For shell scripting
Tons of scripts are available.
Easy development
Enormous big support script archive like CPAN
No one starts to write a Perl scripts from scratch, you choose one from an archive and modify that.
It is a "mature" scripting language.
You may find Perl interpreter on every mission critical environment
Easy to learn

Why Does Perl Not Have Overloaded Functions?

Because you can inspect the argument count, return context, and object types all by yourself.
In Perl, the number of arguments is trivially available to a function via the scalar sense of @_, the return context via want array(), and the types of the arguments via ref() if they're references and simple pattern matching like /^d+$/ otherwise. In languages like C++ where you can't do this, you simply must resort to overloading of functions.

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.

What Are The Three Ways To Empty An Array?

The three different ways to empty an array are as follows

1) You can empty an array by setting its length to a negative number.

2) Another way of empting an array is to assign the null list ().

3) Try to clear an array by setting it to undef, but be aware when you set to undef.

How Do You Work With Array Slices?

An array slice is a section of an array that acts like a list, and you indicate what elements to put into the slice by using multiple array indexes in square brackets. By specifying the range operator you can also specify a slice.

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

Splicing an array means 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.

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

Which Has The Highest Precedence, List Or Terms? Explain?

Terms have the highest precedence in perl. Terms include variables, quotes, expressions in parenthesis etc. List operators have the same level of precedence as terms. Specifically, these operators have very strong left word precedence.

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.

Why Do We Use Perl Scripting?

We use PERL scripting because it is rich in all regular expressions and functional concepts, we can create our own rules to find out particular generalized pattern by using regular expression. PERL supports or compatible in almost 76+ Operating systems and supports more than 3000 modules, called as CPAN (Comprehensive Perl Archive Network) modules.

What Is A Subroutine?

Subroutine is perl is a block of code specially combined/grouped to perform a particular task.Which can be called at any point of time in a perl program.

Advantage using Subroutine

a) helps in modular programming making it easier to understand and maintain.
b)eliminates duplication by reusing the same code/calling the subroutine.

Name An Instance You Used In Cpan Module?

CGI, DBI etc are very common packages used from CPAN. there are thousands of other useful modules.

I Have A Variable Named $objref Which Is Defined In Main Package. I Want To Make It As A Object Of Class Xyz. How Could I Do It?

use XYZ;
my $objref= XYZ->new();

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";

What Is The Difference Between Chop & Chomp Functions In Perl?

chop is used to remove last character,chomp function removes only line endings.

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");

How Would You Replace A Char In String And How Do You Store The Number Of Replacements?

$cnt= ($str=~s/l/i/g);
print $cnt;

How Do You Open A File For Writing?


What's Your Favorite Module And Why?

My Favourite module is Bcoz it can handle almost all the tasks like

1. parsing the form input
2. printiing the headers
3. can handle cookies and sessions and much more

How To Implement Stack In Perl?

Stack is LIFO (Last in First out), In perl that could be inplemented using the push() and shift() functions. push() adds the element at the last of array and shift() removes from the beginning of an array.

Why Do You Program In Perl?

Perl is easy, fast and its fun to code in perl.
Perl is rich with various packages, N/w programming is very easy and there are lot more advantages to say.

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.

Help In Perl?

perldoc -f print

What Is The Use Of "stderr()"?

The special filehandle for standard error in any package.

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.

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"

What Does The Word '&myvariable' Mean?

What Does The Symbol '&' Means? What's Purpose Of It?
&myvariable is calling a sub-routine.

& is used to identify a sub-routine.

What Is Super?

Super refers to current package ancestor.

What Is Rpc? Why Do I Need It?

RPC:A call to a procedure in a different address space. In a traditional procedure call, the calling procedure and the called procedure are in the same address space on one machine. In a remote procedure call, the calling procedure invokes a procedure in a different address space and usually on a different machine.

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)

What Does Ndd Do?

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

What Is Obp And How Do You Access It?

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

How Do You Boot From Cd-rom?

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

What Is /etc/system For?

/etc/system is a kernal file of Solaris OS.

How Do You Boot From A Network With Jumpstart?

boot net - install

What Is Jumpstart?

The Jumpstart feature is an automatic installation process available in the Solaris operating environment. It allows system administrators to categorize machines on their network and automatically install systems based on the category to which a system belongs.

What Is Lom

Short for LAN on motherboard. The term refers to a chip or chipset capable of network connections that has been embedded directly on the motherboard of a desktop, workstation or server. Instead of requiring a separate network interface card to access a local-area network, such as Ethernet, the circuits are attached to the motherboard. An advantage of a LOM system is an extra available PCI slot that is not being used by the network adapter.

How To Create A Package?

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

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

What Is Vts?

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

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.

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.

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)

What Is It Meants By '$_'?

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

What Is The Tk Module?

it provides a GUI interface.

How To Concatinate Strings In Perl?

through . operator

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.

How Do Find The Length Of An Array?


What Does Read() Return At End Of File?

A defined (but false) 0 value is the proper indication of the end of file for read() and sysread().

How Do You Print Out The Next Line From A Filehandle With All Its Bytes Reversed?

print scalar reverse scalar Surprisingly enough, you have to put both the reverse and the into scalar context separately for this to work.

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.

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.

How Shift Command Is Used?

The first value of an array shifted using shift array function and it is returned, which results in array shortening by one element and moves everything from a place to left. If an array is not specified to shift, shift uses @ ARGV, the command line arguments of an array is passed to script or to an array named @.

Explain Different Types Of Eval Statements?

In general, there are two types of eval statements they are:

Eval BLOCK and

An expression is executed by eval EXPR and BLOCK is executed by eval BLOCK. Entire block is executed by eval block, BLOCK. When you want your code passed in expression then first one is used and to parse code in the block, second one is used.

Subscribe to get more Posts :