Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

CTRL M characters ?

by Anonymous Monk
on Jan 31, 2005 at 22:19 UTC ( #426743=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Anyone have any idea why I'm getting CTRL M characters after every line when I write to a file via a CGI script??
I'm openening a file as follows:
open (FILE, "$file") || die "Error unable to open $file: $!\n";
reading the contents into an array:
my @array = <FILE>; close FILE;
Iterating over the array and writing to the same file:
open (WRITE, ">$file") || die "Error: Unable to open $file: $!\n"; foreach (@array) { print WRITE $_; } close WRITE;
??

Replies are listed 'Best First'.
Re: CTRL M characters ? (HTTP)
by tye (Sage) on Feb 01, 2005 at 00:21 UTC

    The HTTP standard specifies that text will be sent with "\r\n" terminating lines (yes, I'm ignoring the breakage of old MACs quite intentionally). So you'll (most likely) get carriage returns in text you receive over HTTP.

    You show us nothing about how you get this text, though, so I'm forced to guess based on your mention of "CGI".

    - tye        

Re: CTRL M characters ?
by Fletch (Chancellor) on Jan 31, 2005 at 22:36 UTC

    First guess is that $file came from a CP/M-ish platform and has \cMs in it to begin with.

      In case the OP is not familiar with what CP/M-ish means, let me expand that a bit.
      • "Unix-ish" systems have a line feed ("\n" or Control-J or "\012") between lines in text files
      • "Mac-ish" systems have carriage returns ("\r" or Control-M or "\015")
      • "CP/M-ish" (usually meaning DOS or Windows) have both ("\r\n")

      For more details, search for "newlines" in perlport

Re: CTRL M characters ?
by nerfherder (Monk) on Jan 31, 2005 at 22:58 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://426743]
Approved by Paladin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2021-10-20 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (81 votes). Check out past polls.

    Notices?