Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the use of the ’$_’ symbol?

Answer»

$ is default input and PATTERN MATCHING SPACE variable in Perl.

2.

How will you remove the duplicate data from @array=("perl", "php”, "per", "asp")?

Answer»

SUB uniqueString {
return keys %{{ map { $_ => 1 } @_ }};
}
@array = ("PERL", "php”, "per", "asp");
print join(" ", @array), "\N";
print join(" ", uniqueString(@array)), "\n";

 

3.

How to add two arrays together ?

Answer»

@sumarray = (@arr1,@ARR2);

4.

What are the types of operator Perl have ?

Answer»
  • ARITHMETIC OPERATORS, +, - ,* etc
  • Assignment operators: += , -+, *= etc
  • Increment/ DECREMENT operators: ++, --
  • String concatenation: ‘.’ operator
  • comparison operators: ==, !=, >, < , >= etc
  • Logical operators: &&, ||
5.

What is the grep function also write the syntax of it?

Answer»

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

6.

How to declare a variable in Perl?

Answer»

We are not REQUIRED to declare a variable EXPLICITLY to reserve MEMORY space, but its automatically when we ASSIGN a VALUE to the variable using an equal sign(=).

7.

How Perl uses an interpreter?

Answer»

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.

8.

Why Perl warnings are important?

Answer»

The Perl warning gives you the most basic way to GET a quality CHECK of CODE that is DEVELOPED by programmers.

9.

How to reuse code explain with an example.

Answer»

Perl provides a reuse code ability which is called inheritance in this child CLASS can use the methods of the parent class.

Example

PACKAGE Parent;
Sub foo
    {
         print("INSIDE A::foo\n");
    }
 
package Child;
@ISA = (Parent);
package main;
Child->foo();
Child->bar();

 

10.

Write a function that is only available inside the scope.

Answer»

$pvt = CALCULATION(5,5);
print("Result = $pvt\n");
SUB Calculation{
my ($fstVar, $secndVar) = @_;
my $SQUARE = sub {
return($_[0] ** 2);
};
return(&$square($fstVar) + &$square($secndVar));
}; OUTPUT: Result = 50

 

11.

What are references in scalars?

Answer»

A REFERENCE is the an ADDRESS of a VARIABLE.

12.

What are the data types we have in perl explain?

Answer»

There are 3 SORTS of data types

  • Scalar :- Scalars could be a string, a number a simple variable or a reference. A dollar sign ($) is the scalar precedent.
  • Arrays :- It’s an ORDERED LIST of scalars, which is accessible by numeric index as it is an index, so it's supposed to START with zero (0). @ is the preceded sign for arrays.
  • Hashes :- Hashes are unordered sets of key or value that would be accessible by USING the key as subscripts. A percentile (%) sign is the precedent.
13.

Read the following lines and differentiate single and double quote.

Answer»

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.

14.

Print hello world using perl also explain it.

Answer»

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

15.

How to install Perl on Windows?

Answer»
  • For windows, you are supposed to HIT on http://strawberryperl.com link.
  • Now CHOOSE the VERSION as per your windows that is 32 bit or 64 bit.
  • To To install the downloaded file click twice on it which will bring up the Perl install wizard, now just accept the default SETTINGS, wait until the installation is finished and here you ready to use.
16.

How to install Perl on and Linux and Unix?

Answer»

INSTALLATION on Linux and UNIX carry same process–

  • Open your browser and hit this URL https://www.PERL.org/get.html.
  • Here you are supposed to download the zipped file.
  • To install this file prompt below commands on cmd.
    $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.

17.

Is Perl consider as case sensitive languge?

Answer»

YES! It is a CASE SENSITIVE LANGUAGE.

18.

What is the current version of Perl?

Answer»

CURRENT VERSION is 5.28.1

19.

What is Subroutine in Perl?

Answer»

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.

20.

What is the socket call in advance Perl ?

Answer»

In an ESTABLISHED network connection, a socket CALL is the FIRST call that CREATES a socket.

21.

Which alternate will you use in case your machine is not running an email server?

Answer»

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

Example

$msg->send('smtp', "smtp.myisp.net", AuthUser=>"id", AuthPass=>"password" );

22.

What is a die function in error handling?

Answer»

Die FUNCTION is a kind of warning that LEADS an exit call. Which means it immediately terminates the execution in case of error occurrence.

Example

CHDIR('/etc') or die "Can't change directory";

23.

What is error handling?

Answer»

When your PROGRAMME takes APPROPRIATE action against the error occurs which MAY OCCUR during the programme execution.

24.

Differentiate Chop & Chomp function.

Answer»

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.