aboutsummaryrefslogtreecommitdiff
path: root/challenge-040/anton-fedotov/perl5/ch-2.pl
blob: 9d03c94de5982a6a344571d02fb4e6ce7b6041e1 (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
#!/usr/bin/env perl

##################################################
#      Perl Weekly Challenge 040, Chapter 2      #
##################################################

use strict;
use warnings;
use v5.10;

my @numbers = (10, 4, 1, 8, 12, 3);
my @indices = (0, 2, 5);

say join ' ', @numbers;

my @arr;
push @arr, $numbers[$_] for @indices;
@arr = sort {$a <=> $b} @arr;

for (@indices) {
    state $i = 0;
    $numbers[$_] = $arr[$i++];
}

say join ' ', @numbers;