1. Write a script to display mirror image of a entered value and also check whether Palindrome?

print("Enter the no. to check for Palindrome : ");
$no = <STDIN>;
chop($no);

$i = 0;

# Store into a array
while($no != 0)
{
@array[$i] = $no % 10;
$no = int($no / 10);
$i++;
}

$i--;
$j=0;
$flag = "true";

# Check for Palindrome
while( ($flag eq "true" )&& ( $j < @array/2) ){
if (@array[$j] != @array[$i])
{
$flag = "false"
}
$i--;
$j++;
}

# Print the result
if( $flag eq "true")
{
print("It is a Palindromen");
}
else
{
print("It is NOT a Palindromen");
}

2. Write a script to generate n prime no.s?

#!c:perlbinperl

$Count = 0;
$pt = 2;
while ( $Count < @ARGV[0] )
{
if (isPrimary($pt))
{
print "$ptn";
$Count++;
}
$pt++;
}

sub isPrimary
{
$flag = 1;
for ($i=2; $i<=$_[0]/2; $i++)
{
if ($_[0] % $i == 0)
{
$flag = 0;
}
}
return $flag;
}

3. Why we use "use lib $path"?

If we are trying to add a module or library files in our
program using require or use statement then it will search
that module or library files in the Perl's default search path.

The statement use lib is used to add the directories to
default search path.

So if the module or library file is not located in the
Perl's default search path then it will find the library
files in the path we have given with the use lib $path.

4. Difference between Perl and Mod_perl?

Perl is a language and MOD_PERL is a module of Apache used
to enhance the performance of the application.

5. How to make the following assignment, as arrayreference assignment?

my $arr_ref=[1,2,3,4,4,elem];

my $ref=[1,2,3,4];
print ref $ref;

ref will return the type of reference.
In this case ref will return as 'ARRAY'.

7. Write a perl script to find whether a given line of text is starting and ending with same word or not?

Lets assume that the text to match is present in a file
say "data.txt".
Following program will print the line containing same
starting and ending word.

open(FILE,"data.txt") or die "cannot open file : $!";

while(<FILE>) {
if($_ =~ /^(w+)s+.*?1$/) {
print "the line is $_ n";
}
}

8. Write a Perl script to find a particular word in a paragraph?

[code]
my $pat;
$pat='Using push we can add multiple items into an array in
a single instance.
If we are trying to add a module or library files in
our program using require or use statement then it will
search that module or library files in the Perl's default
search path.

The statement use lib is used to add the directories
to default search path.

So if the module or library file is not located in
the Perl's default search path then it will find the
library files in the path we have given with the use lib
$path.';

if($pat=~/push/)
{
print "Pattern push get matchedn";
}
[/code]

9. What is the difference between having a parenthesis after module name and without parenthsis after module name?
i.e Package::Module();
and Package::Module;

Package::Module(); This will throw as error,

I think,the question should be as: What is the difference
between,
Package::MyModule qw(); # FIRST
and
Package::MyModule; # SECOND

# FIRST :- This will not import any subroutine from MyModule.
# SECOND :- This will import all the subroutine from the
MyModule.

10. What is the meaning of rigging?

Rigging is use for if we want to give animation for any
object or character then we apply to character or object
internel bone setting(like our bones).that is called
rigging. when apply rigging, then we can give proper
animation.

Download Interview PDF