My little utility generates a Quake3-style shader from a generic input file. The areas that need to be replaced are genericized as so:
The script will open the generic version of the shader, read it in, and keep replacing the strings so long as there are files in the specified directory. Currently it's as follows:
#!/usr/local/bin/perl
#
# autoShader generates a generic shader for all the textures in a directory.
#
# definitions
$shader = 'auto_surf.shader';
$dir = 'test';
# subroutines
sub generateShader
{
print "texture: @_\n";
$outShader = $genericShader;
print $outShader;
# replace $DIR and $TEX
$outShader =~ s/$DIR/$dir/;
$outShader =~ s/$TEX/$file/;
print $outShader;
}
print "----- autoShader -----\n";
print "using directory: $dir\n";
# read in the generic shader
open(INFO, $shader);
$genericShader = <INFO>;
close(INFO);
# loop through the directory
opendir(DIR, $dir) or die"error: cannot find directory $dir. perl output is below.\n$\n";
while (defined($file = readdir(DIR)))
{
next if $file =~ /^\.\.?$/; # skip . and ..
generateShader($dir, $file);
}
closedir(DIR); It seems to not be replacing the $DIR and $TEX tokens. Ideas?