Perl Interview QA

0
265
  • What is Perl Scripting?

Perl is a scripting language which is runs on different platforms like Windows, Linux, Mac. It works with an interpreter. In all the applications, optimization is used.

  • 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

  • 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?

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.
  • 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.

  • 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?

The same level of precedence as Terms is for List operators.

  • 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.

  • Explain Different Types Of Eval Statements?

In general, there are two types of eval statements they are:
• Eval BLOCK and
• Eval EXPR
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.

  • 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.

  • 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 L 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.

  • 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?

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.

  • 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();

  • 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.

  • 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 role By A ‘pack’ In Perl?
    • Pack Converts a list into a binary representation
    • It takes an array or list of values as an argument and packs it into a binary structure, returning the string containing the structure.
  • 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, II, 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 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.

  • 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){
$len–;
$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.

  • How to find occurance of a word in a file in case sensitive manner?

open(FILE,”filename”);
@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?

-For shell scripting
-For CGI
-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

1
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.

  • 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?

The chop function is used to remove last character from a string.

The chomp function removes only line endings.

  • What Is Hash?

Hash is an associative array where data is stored in “key”->”value” pairs.
For example : If 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?

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

  • How Do You Open A File For Writing?

open FILEHANDLE, “>$FILENAME”

  • What’s Your Favorite Module And Why?

My Favourite module is CGI.pm Because it can handle almost all the tasks like
1. parsing the form input
2. printing the headers
3. can handle cookies and sessions and much more

  • How To Implement Stack In Perl?

The Stack is  basically a data structure which uses model of 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 comes with various open source packages, N/w programming is very easy and there are lot more advantages to say.

Perl can be used for different automation programming in the system.

  • 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

  • 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 means for Remote Procedure Call. 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.

  • How To Create A Package?

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

  • How Do You View Shared Memory Statistics?
  • pmap -> lists the virtual memory mappings underlying the given process
  • swap -l -> displays swap usage
  • vmstat -> reports information about processes, memory, paging, block IO, traps,
    and cpu activity
  • prstat -> examines all active processes on the system and reports statistics based
    on the selected output mode and sort order
  • What Is Grep Used For In Perl?

The Grep is mostly 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.

  • 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 ‘$_’?

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

  • What Is The Tk Module?

Tk or Tinker is very popular module for making GUIs using the scripting language platform.

  • How To Concatenate Strings In Perl?

There is  DOT operator(. ) which can be used concatenate two strings

  • What Value Is Returned By alone ‘return;’ Statement?

While returning the scalar, it returns undefined value and for the list it return the list of values. This is a good way for the function to return value during failure as a simple return without the context in which they were called.

  • How Do Find The Length Of An Array?

You can use the [email protected] to get the length of the 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?

For this you basically have to print scalar as reverse, you have to put both the reverse and the inside scalar matter separately for this to work.

  • What Are Scalar Data And Scalar Variables?

Perl uses data types in flexible manner.  The meaning of Scalar is “single thing”, like a number or string. So the concept of other languages for data type like int, float, double and string equals to Perl’s scalar in concept and the numbers and strings are exchangeable here. Scalar variable is a Perl variable that is used to store data. It uses a dollar sign $ prefix and followed by one or more alphanumeric 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 which is to be fetched through the sql statement in a hash format.

  • What Is Cpan?

CPAN is acronym of Comprehensive Perl Archive Network.  It is internet based repository to provide thousands of Perl Modules, source and documentation, and all under GNU/GPL or similar licence.

What Is The Difference Between Exec And System?

While using exec() function, it simply switches to the process which has been given as name and continues to execute it. It never returns. But the system forks off the given process and waits till it complete and then return.

  • What Is The Difference Between For And Foreach?

Foreach and For are different representation of making loop programming model. In a logical parameter there is no such difference in the model wise or performance wise. In a way the perl language interpreter uses same mechanism to implement the For loop.

  • What Is A Regular Expression?

Regular expression is a standard mechanism used in different languages to represent the pattern in a logical model. Using the regular expression you can easily write code to search and find operation.

  • What Is Stderr() In Perl?

Stderr is a error handling standard library in the Perl language.

  • List The Files In Current Directory Sorted By Size ?
  • ls -l | grep ^- | sort -nr

 

SHARE
Previous articleTop 7 common Myths about Interviews
Next articlePython Interview QA
Tanmoy Deb is Founder of Equonix Tech Lab Pvt Limited, which is India's first Commercial Satellite Development Company. He is working 12+ years into embedded, electronics, product development. His designed products raised more than 10Million Dollars from different crowdfunding campaign. He is also an author on different technical books. His hobby is music, creating tools for programmers.

LEAVE A REPLY

Please enter your comment!
Please enter your name here