aboutsummaryrefslogtreecommitdiff
path: root/challenge-331/ysth/perl/ch-1.pl
blob: 053c9b813b858914151c353099d69029dbab323c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use 5.036;

use utf8::all; # utf8 @ARGV

sub grapheme_length($string) {
    scalar( () = $string =~ /\X/g )
}

sub last_word_length($string) {
    # words are made up of letters, numbers, modifiers, and underscore-like punctuation
    grapheme_length reverse($string) =~ /([\pL\pN\pM\p{pC}]+)/ ? scalar reverse $1 : ''
}

sub main() {
    my @inputs = @ARGV;
    for my $string (@inputs) {
        printf "%-30s -> %s\n", $string, last_word_length $string;
    }
}

main() unless caller;