in reply to Writing into files and RegExp

You leave the line endings at the end of your file. Most likely, there is whitespace at the end of each line that you want to remove. Such things can happen for example when you create a file with Windows-style line-endings ("\r\n") and then process that file with a perl which only expects Unix-style line-endings ("\n"). As a quick measure of testing that, you could check for whitespace at the end of the lines:

while (<$IN>) { chomp; warn "Whitespace at end of line $.: >$_<" if /\s+$/; ... };

If that indeed is the case, you can either set the input record separator ($/) to the whitespace sequence, or simply strip off all whitespace.

Replies are listed 'Best First'.
Re^2: Writing into files and RegExp
by PerlingTheUK (Hermit) on Mar 10, 2006 at 10:32 UTC
    Thanks, but that is not the problem. I am using Win32 file with a Win32 Platform. What happens is that a line like
    XYABCDEFG 123451234512341234 1 H 56 65
    becomes
    XYABCDEFG 123451234512341234 1 ^@^@^@^@^@^@^@^@^@^@^@^@...
    with the ^@ extending for about roughly 2000 characters.

    I have tried this several times and the resulting file always has the same size.


    Cheers,
    PerlingTheUK

      You will need to post some data then, which reproduces the problem, as your code does not show anything that I recognize as triggering such behaviour. Please make sure before posting that no sensitive data gets posted and that the posted data actually produces the behaviour you describe. Although I'm no user of Emacs, the ^@ character could be its interpretation of "\0". Which still is weird, but without seeing your input data, it's hard to tell where it comes from. Also, your Perl version (perl -v) might be of interest.

        I cannot reproduce it on a small file and the actual data is half a GByte. However it seems it is more or less my hard disc that is about to die.

        Cheers,
        PerlingTheUK