RosettaCodeData/Task/Determine-if-a-string-is-squeezable/Perl/determine-if-a-string-is-squeezable.pl
2023-07-01 13:44:08 -04:00

21 lines
930 B
Perl

use strict;
use warnings;
use Unicode::UCD 'charinfo';
for (
['', ' '],
['"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ', '-'],
['..1111111111111111111111111111111111111111111111111111111111111117777888', '7'],
["I never give 'em hell, I just tell the truth, and they think it's hell. ", '.'],
[' --- Harry S Truman ', ' '],
[' --- Harry S Truman ', '-'],
[' --- Harry S Truman ', 'r']
) {
my($phrase,$char) = @$_;
(my $squeeze = $phrase) =~ s/([$char])\1+/$1/g;
printf "\nOriginal length: %d <<<%s>>>\nSqueezable on \"%s\": %s\nSqueezed length: %d <<<%s>>>\n",
length($phrase), $phrase,
charinfo(ord $char)->{'name'},
$phrase ne $squeeze ? 'True' : 'False',
length($squeeze), $squeeze
}