Notice the null character in the first example doesn't show up in the others.
[predb24:~/tests] $ cat lines.pl #!/usr/bin/perl open (TEST, ">test.txt"); print TEST "This is a test\n"; #print TEST "This is a test\n"; #print TEST "";<br/> close TEST;<br/> [predb24:~/tests] $ lines.pl [predb24:~/tests] $ od -cx test.txt 0000000 T h i s i s a t e s t \n \ +0 6854 7369 6920 2073 2061 6574 7473 000a 0000017 [predb24:~/tests] $ cat lines.pl #!/usr/bin/perl open (TEST, ">test.txt"); print TEST "This is a test\n"; print TEST "This is a test\n"; #print TEST ""; close TEST; [predb24:~/tests] $ lines.pl [predb24:~/tests] $ od -cx test.txt 0000000 T h i s i s a t e s t \n +T 6854 7369 6920 2073 2061 6574 7473 540a 0000020 h i s i s a t e s t \n 6968 2073 7369 6120 7420 7365 0a74 0000036 #!/usr/bin/perl open (TEST, ">test.txt"); print TEST "This is a test\n"; print TEST "This is a test\n"; print TEST ""; close TEST; [predb24:~/tests] $ lines.pl [predb24:~/tests] $ od -cx test.txt 0000000 T h i s i s a t e s t \n +T 6854 7369 6920 2073 2061 6574 7473 540a 0000020 h i s i s a t e s t \n 6968 2073 7369 6120 7420 7365 0a74 0000036 [predb24:~/tests] $ cat lines.pl #!/usr/bin/perl open (TEST, ">test.txt"); #print TEST "This is a test\n"; #print TEST "This is a test\n"; print TEST "\n"; close TEST; [predb24:~/tests] $ lines.pl [predb24:~/tests] $ od -cx test.txt 0000000 \n \0 000a 0000001

In reply to Why do I sometimes get null characters after the line feed when writing to files? by colint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.