Listing 1.
NewAssignment.pl, called from mprime.sh
David Nicol

The Great Internet Mersenne Prime Search
The Perl Journal, Winter 1997
 
01 #!/usr/bin/perl
02 
03 $RangeMatcher = ’.*?a range of (\d+) .*? from ([\s0-9to,]+)\.’;
04
05 $PreTextB1 = "easiest";       # "These are the easiest exponents to test."
06 $Flags{B1} = "";
07 $PreTextB2 = "little longer"; # "These exponents take a little longer to test"
08 $Flags{B2} = ""
09 $PreTextB3 = "slowest"        # "These are the slowest numbers to test"
10 $Flags{B3} = "";
11 $PreTextR  = "Reclaimed"      # "Reclaimed Ranges" section
12 $Flags{R}  = ""
13 $PreTextF  = "Factoring";     # "Factoring" section
14 $Flags{F}  = "-f ";           # An extra command line flag for 
                                 # factoring composites
15
16 srand(time ^ ($$ + ($$ << 15)));  # Seed the random number generator
17
18 # edit the next line, leaving only the tests you want to consider
19 @Suffixes = qw(B1, B2, B3, R, F);
20
21 # choose which kind of search to perform
22 $Suffix   = $Suffixes[int rand scalar(@Suffixes)];
23 $PreText  = ${’PreText’ . $Suffix};
24 $PreFlags = "-i500000 -l2.1 -p300";       # Command line flags for mprime
25 print "Chose to search for list after <$PreText>\n";
26 
27 # If the network is down, we try until lynx -dump meets our expectations. 
28 until ($RangeListing){
29     # load the "Choose a Range" web page into a variable:
30     $ChooseARangePage = `lynx -dump http://www.mersenne.org/range.htm`;
31     last if ($PortionSize, $RangeListing) = 
               ($ChooseARangePage =~ m/$PreText$RangeMatcher/s);
32
33     # invoke your ppp-down script here, e.g. system( ’ppp-down’ );
34
35     die "Bad data from http://www.mersenne.org/range.htm\n" 
                                      unless $Tries++ < 20;
									  
       # try once every three hours, twenty minutes, for nearly a week
36     sleep 200;     
37
38     # invoke your ppp-up script here, e.g. system( ’ppp-up’);
39 };
40
41 # If you have a fast machine and you want a large portion, uncomment this:
42 # $PortionSize *= 2
43 
44 $RangeListing =~ s/\s//g;            # lose spaces, tabs, newlines
45 @Ranges = split /,/, $RangeListing;  # Split $RangeListing, using "," 
                                        # as a delimiter
46 
47 $MyRange = $Ranges[int rand scalar(@Ranges)];
48
   # narrow MyRange down to a normal size portion
49 ($Low,$High)=split(/to/, $MyRange);  
50 
   # for when there’s a missing chunk
51 unless ($High - $Low < $PortionSize) {    
52     #redefine $MyRange to be a normal portion
53     $High    = $Low + $PortionSize;
54     $MyRange = "$Low $High";
55 };
56 
57 $Assignment = "$Flags{$Suffix} $MyRange $PreFlags";
58 $Hostname   = `hostname`;
59 open(MAIL, "|mail mprime");   # open a pipe to the mail program; 
                                 # assumes mprime is a valid address
60 print MAIL <<"END";
61 Subject: New GIMPS assignment for $Hostname
62 
63     This message is coming from the mprime script, choosing
64     a new assignment for $Hostname.
65 
66     I’ve randomly chosen to do $Assignment, and have registered it
67     with George Woltman. 
68 
69 END
70 
71 open (ASSIGNMENT, ">assignment") or die "Can’t open 
         assignment file, check permissions and ownership";
72 print ASSIGNMENT $Assignment;
73 close ASSIGNMENT;   # Write $Assignment out to the assignment file
74
75 # Send mail to George Woltman to reserve the range.
76 open(MAIL, "|mail -s \"Automated assignment choice: 
                         $Assignment\" woltman\@magicnet.net");
77 print MAIL <<"ENDMAIL";
78 
79 Hi George!
80 
81 My computer has finished its last assignment and 
82 in theory has sent you the results file.
83 
84 I have chosen, at random, from http://www.mersenne.org/range.htm,
85 to do $Assignment
86 
87 A reply to this message should get back to me if I need to change
88 that range by 
89 
90 editing my assignment file, 
91 killing mprime, 
92 and running mprime.sh again.
93 
94 See ya in a couple months!
95 ENDMAIL