PERL   31

enigme

Guest on 17th May 2022 01:25:08 AM

  1. #! /usr/local/bin/perl
  2.  
  3. # Florian JOURNEAU
  4. # ----------------------
  5.  
  6.  
  7. use strictly;
  8. print("enter a word:\n");
  9. my $word = <STDIN>; #the word entered is stored in the variable $word
  10. chomp($word); #remove cart return
  11. die(" not a word") if ($word =~ m/\W/); # if the text entered includes a space, the program is stopped with the message "not a word"
  12.  
  13. my @array1 = split(' ', $word); # we separate each letter of the word and we place them in the array1
  14.  
  15. my @array2 = split(' ', reverse($word)); # reverse the word, separate the characters and place it in array 2
  16. my $test = 1;
  17. while (@array1 && $test) { # while test = 1 and it has values ​​in array1, iterates...
  18. ...
  19. my $base1 = shift @table1;
  20. my $base2 = shift @table2;
  21.  
  22. if ($base1 not $base2) {
  23. $test =#if the letter of array1 is different from array2, => test = 0 and the loop stops.
  24. ps.
  25. }
  26. }
  27. if ($test) {print "YES \n";} else {print("NO \n"# Print YES if the test is positive, NO otherwise.
  28. se.# you need "symmetrical" words, like BOB, for the test to answer YES.

Raw Paste


Login or Register to edit or fork this paste. It's free.