Palindrom Checker

Палиндром — слово или предложение, которое одинаково читается слева направо и справа налево
Эта Perl-программа проверяет, является-ли указанное слово палиндромом, или нет.

#!/usr/bin/perl

if (!@ARGV){
die ("Usage: palindrom.pl word\n");
}

$text = $ARGV[0];

if (length($text) < 4){
die ("Error: Word must be not less than 4 leters\n");
}

if ($text =~ m/(.)(.). ?\2\1/){
print "Result: Match\n";
}
else{
print "Result: Not match\n";
}

Поблагодарить автора

One Response to Palindrom Checker

  1. Функцию reverse уже отменили?

    $text =~ s/\W//g;

    $txet = reverse ($text);

    if ($text =~ /$txet/i){

    print «Result: Match\n»;

    }

    else{

    print «Result: Not match\n»;

    }

Оставить комментарий

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>