>Anthony Akens wrote: >> 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?
>Not really, unless the program you didn't write is in Perl. Nope. Probably C. >> 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. >That sounds about right. I guess you're lucky there isn't a checksum as >well or you wouldn't be able to change anything at all. >> The code I'm using for a file with a 7 character ID is: > use strict; > use warnings; I left out a lot of the code, use strict and warnings are up there, yeah :) >> open (TEMPLATE, "<$template") or die "Could not open Template. ($!)"; >> binmode (TEMPLATE); > >> open (NEW, ">$newfile") or die "Could not open file $dws ($!)"; >What's $dws? Me forgetting to change the variable name. Oops. >> binmode (NEW); >> while (<TEMPLATE>) { >> >> s/REPLACE/$id/; >> print NEW $_; >> } > >> close NEW; >> close TEMPLATE; >Yes, that'll do it, but how do you generate these different >config files in the first place? It sounds like you need to do >it that way rather than hack a generic file. There's no way of >telling what the program expects without the source code. I generate the config "templates" by going in to the app and configuring the settings I want, then copying out that config file. The reason I'm trying to "automate" this is that creating a config file within the application takes ~10 minutes, and there are over 1500 of them to make, that can change on a regular basis. I only need around 10 templates, though. There is no way I can see the source, however I am 100% sure a template done the way I am now works, as long as the orignal and new templates contain strings of the same lengths. >Rob Thanks for the help. -Tony -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]