aboutsummaryrefslogtreecommitdiff
path: root/challenge-059/mohammad-anwar/perl/ch-1.pl
blob: a3cfeed4c4e32fafb9c69cc04c8f5828f677ba04 (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
25
26
27
28
#!/usr/bin/perl

use strict;
use warnings;

my $L = [ 1, 4, 3, 2, 5, 2 ];
my $K = 3;
my $O = split_list($L, $K);

print sprintf("Input:  [ %s ]\n", join (" -> ", @$L));
print sprintf("Output: [ %s ]\n", join (" -> ", @$O));

sub split_list {
    my ($L, $K) = @_;

    my $before = [];
    my $after  = [];
    foreach my $i (@$L) {
        if ($i < $K) {
            push @$before, $i;
        }
        else {
            push @$after, $i;
        }
    }

    return [ @$before, @$after ];
}