## WeBWorK Problems

### need a shell script

by Darwyn Cook -
Number of replies: 2
Our faculty have requested that our students have the ability to generate a new problem using the ProblemRandomize command for all of our problems. It seems to me that adding PGcourse.pl to the list of macro files for all of the problems in the NPL would be the way to go.

So a shell script that searches through pg files, looks at the macros statement and appends PGcourse.pl, if PGcourse.pl and "problemRandomize.pl" are not already there, is what I am looking for.

### Re: need a shell script

by Nandor Sieben -
This is fairly easy to do with perl but it might be easier and less messy to load the needed macros in a macro file like PG.pl that is loaded by every pg file.

### Re: need a shell script

by Gavin LaRose -
Hi Darwyn,

The following may do what you want. It runs in the directory containing the PG files you want to change.

#!/usr/bin/perl -w
use strict;

foreach my $f ( ls *.pg ) { my$file = cat $f; chomp($f );
if ( $file !~ /PGcourse\.pl/ ) {$file =~ s/(loadMacros$$[^)]+?),?(\s*)$$;/$1,$2"PGcourse.pl",\n);/s;
open( OF, ">$f" ); print OF$file;
close(OF);
print "$f.. "; } else { print "[$f].. ";
}
}
print "done\n";


Gavin