#!/usr/bin/perl #author: j. s. leonard 2006 print header(); use CGI ':standard'; # Why are spaces added to array lines when your file # contains linefeeds? Here's an example. # # Note that testout4.txt is correct, but all others # have a space added after the linefeed. # # Also note that testout3.txt is correct, because it # does not contain linefeeds. # # Thanks. open(*FH, "<testin1.txt"); #open file my @Data=<FH>; #read file into array close (*FH); #close file open(*FH, ">testout1.txt"); #open file print FH "@Data"; #read file into array close (*FH); #close file open(*FH, "<testin2.txt"); #open file my @Data=<FH>; #read file into array close (*FH); #close file open(*FH, ">testout2.txt"); #open file print FH "@Data"; #read file into array close (*FH); #close file open(*FH, "<testin3.txt"); #open file my @Data=<FH>; #read file into array close (*FH); #close file open(*FH, ">testout3.txt"); #open file print FH "@Data"; #read file into array close (*FH); #close file open(*FH, "<testin1.txt"); #open file my @Data=<FH>; #read file into array close (*FH); #close file open(*FH, ">testout4.txt"); #open file foreach (@Data) { #loop through array print FH "$_"; #print to file } close (*FH); #close file exit; #========================== # ALREADY TRIED: #========================== # # * Windows, Linux doesn't matter. # * Tested on many different machines. # * # * # * # * # * #========================== # DEPENDENCIES: #========================== # testin1.txt (Normal) #---------------------------- #line1 #line2 #line3 #line4 # testin1.txt HEX (CRt-Lf) #---------------------------- # 6C 69 6E 65 31 0D 0A # 6C 69 6E 65 32 0D 0A # 6C 69 6E 65 33 0D 0A # 6C 69 6E 65 34 # testin2.txt HEX (Lf) #---------------------------- # 6C 69 6E 65 31 0A # 6C 69 6E 65 32 0A # 6C 69 6E 65 33 0A # 6C 69 6E 65 34 # testin3.txt HEX (CRt) #---------------------------- # 6C 69 6E 65 31 0D # 6C 69 6E 65 32 0D # 6C 69 6E 65 33 0D # 6C 69 6E 65 34 #========================== # OUTPUT: #========================== # testout1.txt #---------------------------- #line1 # line2 # line3 # line4 # testout1.txt HEX #---------------------------- # 6C 69 6E 65 31 0D 0A # 20 6C 69 6E 65 32 0D 0A # 20 6C 69 6E 65 33 0D 0A # 20 6C 69 6E 65 34 # testout2.txt HEX #---------------------------- # 6C 69 6E 65 31 0D 0A # 20 6C 69 6E 65 32 0D 0A # 20 6C 69 6E 65 33 0D 0A # 20 6C 69 6E 65 34 # testout3.txt HEX #---------------------------- # 6C 69 6E 65 31 0D # 6C 69 6E 65 32 0D # 6C 69 6E 65 33 0D # 6C 69 6E 65 34 # testout4.txt HEX #---------------------------- # 6C 69 6E 65 31 0D 0A # 6C 69 6E 65 32 0D 0A # 6C 69 6E 65 33 0D 0A # 6C 69 6E 65 34

In reply to spaces after linefeeds when printing arrays by jsleonard

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.