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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain perl. What are the advantages of programming in perl?

758


How to dereference a reference?

730


What is Perl?

739


How to read file into hash array ?

754


What are the arguments and what do they mean in perl programming?

710






What is automatic error handling in perl?

684


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

719


Hi, I am a accountant. I am preparing a balance sheet but because of staff shortage and time pressures I cant complete it on time. There is lot of common data with last years which I need not retype and I can manage by editing last year’s balance sheet ? Is their any software on net where I can do this easily??

1923


Explain the execution of a program in perl.

666


What interface used in PERL to connect to database? How do you connect to database in Perl?

696


What are hashes?

694


Explain 'grep' function.

729


Explain the difference between die and exit in perl?

598


How to read a file into a hash array?

761


How can you call a subroutine and identify a subroutine?

713