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.

> 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;

> open (TEMPLATE, "<$template") or die "Could not open Template. ($!)";
> binmode (TEMPLATE);
>
> open (NEW, ">$newfile") or die "Could not open file $dws ($!)";

What's $dws?

> 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.

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to