aboutsummaryrefslogtreecommitdiff
path: root/challenge-008/zapwai/perl/ch-2.pl
blob: 052a4f37519d23b386dc9b55bdf54e1619435253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use v5.30;
sub center {
    my @list = @_;
    my $long = 0;
    foreach (@list) {
	$long = length $_ if (length $_ > $long);
    }
    my $cnt;
    do {
	$cnt = 0;    
	foreach (@list) {
	    if (length $_ < $long) {
		$cnt++;
		add_space($_);
	    }
	}
    } while ($cnt != 0);
    return \@list;
}

sub add_space { $_[0] = " $_[0] "; }

my $ref = center("This", "is", "a test of the", "center function");
say foreach (@$ref);