Script for calculate primes.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

23 lines
586 B

use 5.30.3;
use strict;
use warnings;
die "No argument received." unless scalar @ARGV;
my $n = $ARGV[0];
die "That does not look like like an integer positive number." unless $n =~ /^\d+$/;
my @prime_list;
for my $current_number ( 2 .. $n ) {
my $is_prime = 1;
for my $prime ( @prime_list ) {
unless ($current_number % $prime) {
$is_prime = 0;
last;
}
}
push @prime_list, $current_number if $is_prime;
}
say 'Your primes are: ' . (join ', ', @prime_list) . '.';
say 'The number of primes is: ' . ( scalar @prime_list ) . '.';