| 1 | package String::CommonSuffix; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 8 | 2 | our $DATE = '2025-08-02'; # DATE | |||||||||
| 9 | 2 | our $DIST = 'String-CommonPrefix'; # DIST | |||||||||
| 10 | 2 | our $VERSION = '0.021'; # VERSION | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use Exporter qw(import); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | our @EXPORT_OK = qw( | |||||||||
| 15 | common_suffix | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 6 | ▶ | sub common_suffix { | ||||||||
|
Subroutine
common_suffix: called CC=7 SCAR=20.0
Pod
documented
| |||||||||||
| 19 | 6 | require List::Util; | |||||||||
| 20 | |||||||||||
| 21 | 6 | ▶ | return undef unless @_; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 6 | my $i; | |||||||||
| 23 | L1: | ||||||||||
| 24 | 6 | ▶ | for ($i = 0; $i < length($_[0]); $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 6 | for (@_[1..$#_]) { | |||||||||
| 26 | 9 | ▶ | if (length($_) < $i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | $i--; last L1; | |||||||||
| 28 | } else { | ||||||||||
| 29 | 9 | ▶ | last L1 if substr($_, -($i+1), 1) ne substr($_[0], -($i+1), 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | } | ||||||||||
| 31 | } | ||||||||||
| 32 | } | ||||||||||
| 33 | 6 | ▶ | $i ? substr($_[0], -$i) : ""; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 2 | 1; | |||||||||
| 37 | # ABSTRACT: Return suffix common to all strings | ||||||||||
| 38 | |||||||||||
| 39 | __END__ | ||||||||||