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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

How to check the status of airplane mode (enable/disable) in perl for Android mobile?

2617


Which has highest precedence in between list and terms? Explain?

450


Which statement has an initialization, condition check and increment expressions in its body? Write a syntax to use that statement.

558


Explain what is the scalar data and scalar variables in Perl?

575


How can information be put into hashes?

547






Explain the difference between declarations of 'my' and 'local' variable scope in perl?

515


How do you match one letter in the current locale?

567


What does next statement do in perl?

587


What are stdin, stdout and stderr?

525


What are scalars in perl?

551


Why to use perl scripting?

537


How to disable the mod_perl from apache_server as i have used perlfect search on the site and its pagination is not working and the remedy is to disable the mod_perl.

1805


What is v-strings?

614


How do I sort a hash by the hash value?

568


How do I send e-mail from a Perl/CGI program on a Unix system?

597