Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Platform: Windows XP & 2000, Perl: Activestate 5.6.1

Problem:

I have an application configuration file that has an encryption header (jibberish) that is required for the application. All workstations with this application require an identical configuration file except for two fields containing IP and host information. When doing an in-place edit of the file I am unable to capture the header the script/perl thinks the file is at the end and only returns a few of the characters. It appears that the in-place is unable to handle the null value character symbols. Also, if the file is opened in notepad or other editors I am able to see the header (jibberish) but I am unable to copy/paste it or I'm unable to copy/paste it exactly depending on the editor. If I manually open the config file and edit the two fields via notepad and save the changes it works and the application recognizes the config file. But I need to automate this process. Does anyone have any experience with this type of problem, thank you.

Header

ÐÏࡱá >  þÿ       + þÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿþÿÿÿþÿÿÿ     +                   +  ! " # $ % & ' ( ) * + , - . / +0 1 2 3 4 5 6 7 8 þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿR o o t E n t r y +   ÿÿÿÿÿÿÿÿ + Á] ªÆþÿÿÿ C o n t e n t s +  ÿÿÿÿÿÿÿÿÿÿÿÿ + aj + ÿÿÿÿÿÿÿÿÿÿÿÿ + + ÿÿÿÿÿÿÿÿÿÿÿÿ + ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿrator, rcAS400Default

Command Line Version Of In-Place
X:\>perl -i.bak -p test.pl adp.rsf

20051223 Janitored by Corion: Added <code>...</code> around the header

Replies are listed 'Best First'.
Re: In-Place Edit - Null Characters
by jmcnamara (Monsignor) on Dec 23, 2005 at 01:07 UTC

    The solution is to binmode the filehandle so that any ^Z characters in the binary data don't act as end of file characters.

    However, afaik, it isn't possible to binmode STDOUT while using -i like this on Window.

    As such, I'd suggest opening the input file in read/write mode, binmode the filehandle, seek to the correct offset in the file and overwrite the IP address (using pack if necessary).

    As an aside, the file header isn't actually gibberish. It looks like a OLE container document which you could extract data from using OLE::Storage_Lite if you so wished (but you almost certainly don't :-)).

    --
    John.

      Hey John,

      In case no one has told you lately...You Da Man!!!
      It worked, thanks.
Re: In-Place Edit - Null Characters
by GrandFather (Saint) on Dec 23, 2005 at 01:25 UTC

    Your problem character, as mentioned in other posts, seems to be Ctrl-Z (between the ± and the á). However I can't reproduce the problem you are having using the sample code below with AS Perl 5.8.7 on Windows XP. Can you make the minimum required changes to the sample code to demonstrate your problem?

    use warnings; use strict; open outFile, '>', 'test.rsf'; print outFile "ÐÏࡱá >  þÿ\nThis is plain text"; close outFile; local @ARGV = ('test.rsf'); local $^I = '.bak'; while (<>) { chomp; print STDOUT (length $_) . " >$_<\n"; print ">$_<\n"; }

    Prints:

    30 >ÐÏࡱá >  þÿ< 18 >This is plain text<

    DWIM is Perl's answer to Gödel
Re: In-Place Edit - Null Characters
by Corion (Patriarch) on Dec 23, 2005 at 00:21 UTC

    Perl stops reading the file at the first ^Z character, because -i.bak-Mode does not enable binmode. The following oneliner should work:

    perl -i.bak -e "BEGIN{binmode STDOUT}" -p test.pl adp.rsf

    As you don't post any code, it's hard to give you a more elegant version though.

      You need to binmode STDIN too!
      Thanks for the quick response. I tried your suggestion, but got the same result where only a few of the (jibberish) characters were returned, ÐÏࡱ

      I didn't post the contents of test.pl because it can really be anything. The real code will does a substitution for host name and IP after it gets past (supposed to get past) the header, but for the test I just have rem statements in test.pl since it is my understanding that the command line does the while <> operation and print loop.

        If you know its not test.pl then what is it? Realy, honestly, post the code so we can help.


        ___________
        Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;