#!/usr/bin/perl -w use strict; use File::Basename; my $plProgName = basename($0); my $plBaseName = fileparse($plProgName,'\.[^\.]*'); my $input = $ARGV[0] || &usage; my $fail = 0; if ( $input =~ /[a-z]/i ) { &usage(2); } print "Big numbers will take a little while...\n\n" if ( $input > 100000 ); for ( 1 .. $input ) { my $up = $_; my $last_digit = substr($up,length($up) - 1,1); my $mod = $input % $up; next if ( $last_digit == 5 or $last_digit = 0 ); if ( $mod == 0 ) { $fail++; # print "\$fail: $fail\n"; unless ( $input == 1 or $input == 2 or $input == 5 ) { if ( $input == $up and $fail == 2 ) { print "$input is a prime\n"; exit(0); } } else { print "$input is a prime\n"; exit(0); } } } print "$input is \c[[1mnot\c[[m prime.\n"; sub usage { my $errcode = shift || 1; print "\nUsage: $plProgName integer\n\n"; exit($errcode); }