write a script to display mirror image of a entered value
and also check whether Palindrome
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
How do you match one letter in the current locale?
What arguments do you frequently use for the Perl interpreter and what do they mean?
List the files in current directory sorted by size ?
What are the advantages of c over Perl?
what is the difference between require and use in perl?
Explain join function in perl?
How can you call a subroutine and identify a subroutine?
You want to connect to sql server through perl. How would you do that?
You want to concatenate strings with perl. How would you do that?
How we can navigate the xml documents?
What is the difference between die and exit in perl?
There are some duplicate entries in an array and you want to remove them. How would you do that?