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

If EXPR is an arbitrary expression, what is the difference between $Foo::{EXPR} and *{"Foo::".EXPR}?

0 Answers  


Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.

0 Answers  


Explain lists in perl?

0 Answers  


What is boolean context?

0 Answers  


Write a cgi program to show the header part?

0 Answers  






What value is returned by a lone `return;’ statement?

0 Answers  


How to count no of occurrence of a unique patterns in perl?

4 Answers   Ness Technologies,


There are two types of eval statements i.e. Eval expr and eval block. Explain them.

0 Answers  


What is cpan in perl?

0 Answers  


How do I replace every TAB character in a file with a comma?

0 Answers  


Define say() function in perl?

0 Answers  


how to connect cisco switch uisng perl script

0 Answers   ABC,


Categories