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
What are the advantages of programming in Perl?
Perl is easier to understand due to its simple syntax
-is easier to use due to its flexibility
-is easily readable
What factors do you take into consideration to decide if Perl is a suitable programming language for a situation?
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 license for the programming language.
Explain the different types of data Perl can handle.
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 which use a key value as index instead of numerical indexes. Use % as prefix.
What is the importance of Perl warnings? How do you turn them on?
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 possible anomaly.
When used gives out warnings about the possible interpretation errors in the script?
Strict: Strict is a pragma which 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 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.
Explain different types of Perl Operators.
-Arithmetic operators, +, – ,* etc
-Assignment operators: +=, -+, *= etc
-Increment/ decrement operators: ++, —
-String concatenation: ‘.’ operator
-comparison operators: ==, !=, >, < , >= etc
-Logical operators: &&, ||,!
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.
Why aren’t Perl’s patterns regular expressions?
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 previous state. A pattern /([ab]+)c\1/ requires the state machine to remember old states, and thus disqualifies such patterns as being regular expressions in the classic sense of the term.
What is hash in Perl?
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.
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.
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.
Does Perl have reference type?
Yes. Perl can make a scalar or hash type reference by using backslash operator.
What is ‘->’ in Perl?
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
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. <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.
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 It takes a list of values and converts it into a string. The string contains a con-catenation 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
How to implement stack in Perl?
Through push () and shift () function. push adds the element at the last of array and shift () removes from the beginning of an array.
What is Grep used for in Perl?
Grep is used with regular expression to check if a particular value exists in an array. It returns 0 it 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.