I've written a program that both reads from and writes to standard text files. The program creates the text file so that each line contains a specific chunk of information. The problem I'm experience is that some of the lines I want to write out to the file are longer than the, I guess, the Windows allowed lengths (if there is such a thing). When I open up the file in Notepad, the lines are not maintained and everything is overlapping. In Wordpad, however, the file looks how I expected it to, one long chunk of information per line.

This is what I want:
information line 0000000000000000000000000 information line 1111111111111111111111111 information line 2222222222222222222222222
This is what I get:
information line 000000 0000000000 information line 111111 1111111111 information line 222222 2222222222
The problem comes when I am attempting to read from the files. I do a @array = <FILE> to get all of the lines into the array, but the lines aren't seperated like they are suppose to be. Why aren't the lines coming in like the way they are when opened in Wordpad?

After the program writes the files, they are saved as standard txt extensions. I opened them up in Wordpad and saved them in the Unicode format. This made the file appear correctly in both Notepad and Wordpad, but the program still didn't interact with them correctly.

I tried one last thing and save them from Unicode back to a txt document using Wordpad. This suprisingly made everything work. They looked the way they should and the program worked correctly.

What is causing this problem? Does Windows tack on endlines where it sees fit or something? How do I get around this. I don't think I had this problem on Linux. How do I store the file so that when I want to store chunks of information seperated by lines, they are actually stored that way?!? Is there another file extension I should try? Thanks in advance. -Eric

In reply to automatic endlines when saving txt file under windows? by emilford

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.