aboutsummaryrefslogtreecommitdiff
path: root/challenge-253/barroff/perl/ch-1.pl
blob: 565cf93d1a340f847c739cd26f51d3e47e4a634f (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
29
30
31
#!/usr/bin/env perl

use v5.38;

sub split_strings ( $separator, @words ) {
    my @res = grep( { length($_) > 0 }
        map( { split( /\Q$separator\E/, $_ ) } @words ) );

    return \@res;
}

sub MAIN() {
    if (@ARGV) {

        #| Run on command line argument
        say split_strings( $ARGV[1], @ARGV[ 2 .. -1 ] );
    }
    else {
        #| Run test cases
        use Test2::V0 qw( is plan );
        plan 2;

        is split_strings( ".", ( "one.two.three", "four.five", "six" ) ),
          [ "one", "two", "three", "four", "five", "six" ],
          'works for ("one.two.three","four.five","six")';
        is split_strings( '$', ( '$perl$$', '$$raku$' ) ), [ "perl", "raku" ],
          'works for ("$perl$$", "$$raku$")';
    }
}

MAIN();