write a script to display mirror image of a entered value
and also check whether Palindrome

Answers were Sorted based on User's Feedback



write a script to display mirror image of a entered value and also check whether Palindrome..

Answer / dheeraj

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

print "Palindrom \n" if ($rev eq $no);

#Perl cannot identify the datatype until we force operation
on it;

Is This Answer Correct ?    7 Yes 2 No

write a script to display mirror image of a entered value and also check whether Palindrome..

Answer / narayan singh

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 Palindrome\n");
}
else
{
print("It is NOT a Palindrome\n");
}

Is This Answer Correct ?    4 Yes 0 No

write a script to display mirror image of a entered value and also check whether Palindrome..

Answer / guest

# Reverse a string and check if it is palindrome

my $str = "A man, a plan, a cat, a canal – Panama!"; # a
multiple word string

@arr = split //, $str;
my $revstr;
for (0..$#arr) {
$revstr .= join (//, pop(@arr));
}
print "reversed string: $revstr\n";

my $mod_str = $str;
$mod_str =~ (s/[\W]//g);
$revstr =~ (s/[\W]//g);

print "$str is a palindrome \n" if ( lc($mod_str) eq lc
($revstr) );

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More CGI Perl Interview Questions

There are some duplicate entries in an array and you want to remove them. How would you do that?

0 Answers  


What is perl? What is the basic command to print a string in perl?

0 Answers  


What are the various advantages and disadvantages of perl?

0 Answers  


Show the use of sockets for the server and client side of a conversation?

0 Answers  


Which feature of Perl provides code reusability ? Give any example of that feature.

1 Answers  


What are the options that can be used to avoid logic errors in perl?

0 Answers  


Explain different types of perl operators.

0 Answers  


What does the qx{ } operator do?

0 Answers  


Why aren't Perl's patterns regular expressions?

0 Answers  


How to merge two arrays in perl?

0 Answers  


What is the difference between use and require in perl programming?

0 Answers  


What is the difference between die and exit in perl?

0 Answers   HCL,


Categories