Blob


1 #!/usr/bin/perl
2 use utf8;
3 use strict;
4 use warnings;
6 use v5.12;
8 my %patterns = (
9 Gilligan => qr/(?:Wiley )?Gilligan/,
10 'Mary-Ann' => qr/Mary-Ann/,
11 Ginger => qr/Ginger/,
12 Professor => qr/(?:The )?Professor/,
13 Skipper => qr/Skipper/,
14 'A Howell' => qr/Mrs?. Howell/,
15 );
17 rightmost(
18 'There is Mrs. Howell, Ginger, and Gilligan',
19 @patterns{ sort keys %patterns }
20 );
22 sub rightmost {
23 my( $string, @patterns ) = @_;
25 my $rightmost = -1;
26 while( my( $i, $pattern ) = each @patterns ) {
27 my $position = $string =~ m/$pattern/ ? $-[0] : -1;
28 $rightmost = $position if $position > $rightmost;
29 }
31 return $rightmost;
32 }