Debian Codegraph @

demo/kitchen-sink/docs/perl.pl

raw
1 #!/usr/bin/perl
2 =begin
3 perl example code for Ace
4 =cut
5
6 use v5.10;
7 use strict;
8 use warnings;
9
10 use List::Util qw(first);
11 my @primes;
12
13 # Put 2 as the first prime so we won't have an empty array
14 push @primes, 2;
15
16 for my $number_to_check (3 .. 200) {
17 # Check if the current number is divisible by any previous prime
18 # if it is, skip to the next number. Use first to bail out as soon
19 # as we find a prime that divides it.
20 next if (first {$number_to_check % $_ == 0} @primes);
21
22 # If we reached this point it means $number_to_check is not
23 # divisable by any prime number that came before it.
24 push @primes, $number_to_check;
25 }
26
27 # List out all of the primes
28 say join(', ', @primes);