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