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

What does `$result = f() .. g()' really return?

579


What does localtime() do in perl?

579


How to concatenate strings with perl?

483


What is the function of cgiwrap in cgi programming?

501


How to start perl in interactive mode?

572






What are the advantages and disadvantages of perl language?

496


What is v-strings?

617


What is Perl?

574


What are prefix dereferencer?

518


What's the difference between /^Foo/s and /^Foo/?

561


How to read a directory in perl?

546


Difference between the variables in which chomp function work ?

625


Where do we require ‘chomp’ and what does it mean?

528


What does the’$_’ symbol mean?

583


I have one question regarding to eval function. I know eval function is use for error checking but I am not able to understand below line. eval \'exec perl -S $0 ${1+\"$@\"}\' if 0; $0 for script name $@ set if error occur

1620