Perl is an open source programming language generally developed for text manipulation, or we could say text editing. It is currently widely used for the task like web development, system administration, GUI development, network programming and more. Officially Perl does not have an acronym, but in backronyms people used it as Practical Extraction and Report Language. Are you for looking for Perl interview questions? As a Perl developer, you would want to know the best possible Perl interview questions and answers for freshers and experienced that you might be asked in your job Interview.
Here in this article, we will be listing frequently asked Perl Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.
Current version is 5.28.1
Yes! It is a case sensitive language.
Installation on Linux and Unix carry same process–
https://www.perl.org/get.html
.$tar -xzf perl-5.x.y.tar.gz
$cd perl-5.x.y
$./Configure -de
$make
$make test
$make install
Perl has a standard location to install it in /usr/local/bin
and its libraries will be installed in /usr/local/lib/perlXX
, XX is the version of Perl that you have installed.
Once you have done with all this process then you can check Perl version typing Perl –v on cmd.
$perl -e 'print "Hello World\n"'
-e represent perl interpreter at command line while $ is prompt here. Perl file will be saved with dot (. pl) pl extension.
1. print "Hello, world\n";
2. print 'Hello, world\n';
Both will gives you different result like this :-
Hello, world
Hello, world\n$
Also quotes interpolate variables and special characters, whereas same thing does not work for single.
There are 3 sorts of data types
$pvt = Calculation(5,5);
Output: Result = 50
print("Result = $pvt\n");
sub Calculation{
my ($fstVar, $secndVar) = @_;
my $square = sub {
return($_[0] ** 2);
};
return(&$square($fstVar) + &$square($secndVar));
};
Perl provides a reuse code ability which is called inheritance in this child class can use the methods of the parent class.
Package Parent;
Sub foo
{
print("Inside A::foo\n");
}
package Child;
@ISA = (Parent);
package main;
Child->foo();
Child->bar();
The Perl warning gives you the most basic way to get a quality check of code that is developed by programmers.
The program is compiled into the parse tree by the interpreter which ignores words, spaces or marks after a pound symbol. Once parse tree conversion will be done it will execute it immediately. We know Perl as an interpreted language, which converts the program into bytecode before execution. Moreover, it does not store compiled file.
The grep function is used as a filter an array list that runs a regular expression and returns true and evaluated element.
Syntax @List = grep(Expression, @array)
.
@sumarray = (@arr1,@arr2);
sub uniqueString {
return keys %{{ map { $_ => 1 } @_ }};
}
@array = ("perl", "php”, "per", "asp");
print join(" ", @array), "\n";
print join(" ", uniqueString(@array)), "\n";
$ is default input and pattern matching space variable in Perl.
Chop function and Chomp function both are used to eliminate the last character from an expression, each element of the list but in case of chomp function if values of elements match only then chomp will follow the elimination term. That is the reason why chomp is preferable more than chop.
When your programme takes appropriate action against the error occurs which may occur during the programme execution.
Die function is a kind of warning that leads an exit call. Which means it immediately terminates the execution in case of error occurrence.
chdir('/etc') or die "Can't change directory";
We can go with SMTP Server which is available at a remote location along with requiring information as Id-password and URL. Once you get all these details to share your information to send()
method
$msg->send('smtp', "smtp.myisp.net", AuthUser=>"id", AuthPass=>"password" );
In an established network connection, a socket call is the first call that creates a socket.
A group of statements that perform a task side by side is called a subroutine. Code deviation is also provided by subroutine so that each can perform a specific task at the same time.