Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 23rd, 2005, 3:47 PM   #1
niteice
Programmer
 
niteice's Avatar
 
Join Date: Aug 2005
Posts: 98
Rep Power: 4 niteice is on a distinguished road
Send a message via AIM to niteice
Simple string substitution..

My little utility generates a Quake3-style shader from a generic input file. The areas that need to be replaced are genericized as so:
textures/$DIR/$TEX_d

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?
niteice is offline   Reply With Quote
Old Dec 26th, 2005, 12:25 AM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
I haven't read the -entire- script, but just glancing, I suggest adding the "g" to your substitution syntax.

$outShader =~ s/$DIR/$dir/g;
$outShader =~ s/$TEX/$file/g;
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:55 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC