Q1) When do you use Perl for programming?

Ans: PERL is a free open source language. PERL is used to develop web-based applications even though libraries are available to program web server applications, database interfaces, and networking components

Q2) What are the advantages of programming in Perl?

Ans: Perl is easier to understand due to its simple syntax -is easier to use due to its flexibility -supports OOP -is easily readable

Q3) What factors do you take into consideration to decide if Perl is a suitable programming language for a situation?

Ans: If the application to be developed is web-based, Perl provides a lot of flexibility in programming such applications and is most popularly used. As PERL is free, we can save on the cost of acquiring a license for the programming language.

Q4) Explain the different types of data Perl can handle.

Ans:

  • Scalars: store single values and are preceded by $ sign
  • Arrays: store a list of scalar values and are preceded by @ sign 
  • Hashes: store associative arrays that use a key-value as index instead of numerical indexes. Use % as a prefix.

Inclined to build a profession as Perl Scripting Developer? Then here is the blog post on, explore Perl Scripting Training

Q5) What is the importance of Perl warnings? How do you turn them on?

Ans: Warnings are one of the most basic ways in which you can get Perl to check the quality of the code that you have produced. Mandatory warnings highlight problems in the lexical analysis stage. Optional warnings highlight cases of a possible anomaly.

Q6) When used give out warnings about the possible interpretation errors in the script?

Ans: Strict: Strict is a pragma that is used to force checks on the definition and usage of variables, references, and other bare words used in the script. This can be invoked using the use of the strict command. If there are any unsafe or ambiguous commands in the script, this pragma stops the execution of the script instead of just giving warnings.

Q7) Explain different types of Perl Operators.

Ans:

  • Arithmetic operators, +, – ,* etc
  • Assignment operators: +=, -+, *= etc
  • Increment/ decrement operators: ++, —
  • String concatenation: ‘.’ operator
  • comparison operators: ==, !=, >, < , >= etc
  • Logical operators: &&, ||,!

Q8) What is Perl one-liner?

Ans: 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.

Q9) Why aren’t Perl’s patterns regular expressions?

Ans: Because Perl patterns have back-references. A regular expression by definition must be able to determine the next state in the finite automaton without requiring any extra memory to keep around the previous state. A pattern /([ab]+)c1/ requires the state machine to remember old states, and thus disqualifies such patterns as being regular expressions in the classic sense of the term.

Q10) What is a hash in Perl?

Ans: A hash is like an associative array, in that it is a collection of scalar data, with individual elements selected by some index value which essentially are scalars and called as keys. Each key corresponds to some value. Hashes are represented by %followed by some name.

Q11) What does Perl do if you try to exploit the execve (2) race involving setuid scripts?

Ans: 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.

Q12) Why does Perl not have overloaded functions?

Ans: 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.

Q13) Does Perl have a reference type?

Ans: Yes. Perl can make a scalar or hash type reference by using the backslash operator.

Q14) What is ‘->’ in Perl?

Ans: It is a symbolic link to link one file name to a new name. so let’s say we do it likefile1-> file2, if we read file1, we end up reading file2

Q15) What is a subroutine?

Ans: The subroutine is Perl is a block of code especially combined/grouped to perform a particular task. Which can be called at any point in time in a Perl program. <br><br>Advantage using Subroutine<br> a) helps in modular programming making it easier to understand and maintain<br> b) eliminates duplication by reusing the same code/calling the subroutine.

Q16) What is meant by a ‘pack’ in Perl?

Ans: 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 It takes a list of values and converts it into a string. The string contains a concatenation of the converted values. Typically, each converted values looks like its machine-level representation. for example, on 32-bit machines, a converted integer may be represented by a sequence of 4 bytes

Q17) How to implement a stack in Perl?

Ans: Through push () and shift () function. push adds the element at the last of the array and shift () removes from the beginning of an array.

Q18) What is Grep used for in Perl?

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

Q19) How to code in Perl to implement the tail function in unix?

Ans: 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 increasing 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.