Hi all,
I'm doing a text replace in a binary file, which works fine as long as the
text I replace it with is the exact same length. If the text I put in is longer or
shorter, the program that reads the file (not one I wrote) chokes and spews
out a bunch of garbage. Is there a way in perl to deal with that?
This is for a config file, so what I'm doing is having the user select which
generic config template to use, and inputting their "id" and it generates a
config file with their ID in it.
The string I'm inputting is always going to be 5, 6, or 7 characters long. The
only work around I've found for this is to make a config file each with a default
string of the appropriate length. The problem is that I'm ending up needing
three times as many config files as it seems I need to.
The code I'm using for a file with a 7 character ID is:
open (TEMPLATE, "<$template") or die "Could not open Template. ($!)";
binmode (TEMPLATE);
open (NEW, ">$newfile") or die "Could not open file $dws ($!)";
binmode (NEW);
while (<TEMPLATE>) {
s/REPLACE/$id/;
print NEW $_;
}
close NEW;
close TEMPLATE;
-Tony
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]