Creating a new file something going wrong

Discussion in 'Perl Misc' started by riderchap, Jul 18, 2006.

  1. riderchap

    riderchap Guest

    I am opening a new file and writing something to that file and then
    closing it. Now note down the size of file, let it be n bytes.
    Then when I open the newly created file using vi make a change undo
    that change and save and close it, now see the size of the file is n+1
    bytes.

    Also when I open the Perl program generated file in vi, vi will say
    "Last line is not complete", why is that? After the
    change-undo-save-close by vi, when I reopen the file in vi the vi is
    not saying "Last line is not complete".

    Here is the sample test script I used.

    open (OUT_FILE, ">testfile");
    print OUT_FILE "Hello World";
    close (OUT_FILE);

    After Perl program run the size of file is 11bytes. (Hello World is 11
    characters). After opening in vi insert a charater then delete that
    character then save and close. Now the file size is showing as 12
    bytes.
    What is vi writing there?
    Or what character is my Perl program missing to write?
    Why vi says "Last line is not complete", when opening the file created
    by the Perl program?

    Thanks!!!!!!!
    Kannan

    Note: The file I create through my Perl program has to be used by
    another C program and that C program is not reading the last line of
    the file correctly. Please help.
     
    riderchap, Jul 18, 2006
    #1
    1. Advertisements

  2. riderchap

    jue Guest

    vi writes a "\n" at the end of your "incomplete" line.

    Thomas
     
    jue, Jul 18, 2006
    #2
    1. Advertisements

  3. riderchap

    Brian Wakem Guest


    The character will almost certainly be a line feed (ASCII 10).

    I don't see why the C program should have a problem with this unless it is
    written in such a way that it needs each line to end with a line feed, in
    which case make sure you write one at the end of each line in the file.

    print OUT_FILE "Hello World\n";
     
    Brian Wakem, Jul 18, 2006
    #3
  4. riderchap

    Ted Zlatanov Guest

    The last line is not complete (according to vi) because it doesn't end
    with a newline character. vi appended it.

    Here's the easy way to see the difference:
    Hello World> vi testfile
    .... insert and then delete a character, then save ...
    See how the file ends with a newline the second time?

    You can print "Hello World\n" in line 2 of your code to achieve the
    same result.

    Ted
     
    Ted Zlatanov, Jul 18, 2006
    #4
  5. riderchap

    riderchap Guest

    Thanks folks!!!

    I tried all crap ctl Z etc... don't know why didn't try a simple "\n".

    Brian Wakem, that C program is written by somebody else and I have to
    dig out that big C program to find out what he is doing there.

    Thanks again guys.

    -Kannan
     
    riderchap, Jul 18, 2006
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.