CRLF problem

Any other programming language that is not covered in the Web Scripting category.

CRLF problem

Postby zapad on Mon Dec 12, 2005 2:31 pm

I use perl and when I try to get file via http (I use IO::Socket::INET) it is damaged. Every \x0A byte is replaced in it on \x0D\x0A. How to fix it .

P.S. I can not use other modules !!!
zapad
Newbie
Newbie
 
Posts: 5
Joined: Mon Dec 12, 2005 1:35 pm

Postby ravenhair on Mon Dec 12, 2005 7:45 pm

can we see the script?
ravenhair
Regular
Regular
 
Posts: 80
Joined: Tue Nov 08, 2005 5:51 pm

Postby eosp on Tue Dec 13, 2005 3:12 pm

var a is the input you get from the script.

a ~= s/\x0D\x0A/\x0A/g;

Or something ike that--I'm more of a C coder myself.
eosp
Contributer
Contributer
 
Posts: 21
Joined: Tue Dec 13, 2005 4:27 am
Location: Nowhere

Postby mm_freak on Fri Dec 16, 2005 8:12 am

The file isn't damaged. In fact, everything is alright. It just shows that the file has certainly been written on a Windows system. But as long as you don't know why the file is 'damaged', and how you could 'fix' it, you shouldn't be writing network applications (no matter how small they are).
I'm x^10 + x^8 + x^5 + x^4 + x^3 + 1, so don't mess with me!
mm_freak
Moderator
Moderator
 
Posts: 635
Joined: Sun Sep 11, 2005 12:29 pm
Location: Baden-Wuerttemberg (Germany)

Postby De Kus on Sun Dec 18, 2005 2:01 pm

generally you should transfer in binary mode, if not using human readable files Very Happy. in that case the file syste will not try to convert to your local encoding Smile.
Image
User avatar
De Kus
Phoenix Veteran
Phoenix Veteran
 
Posts: 305
Joined: Mon Mar 14, 2005 2:15 pm
Location: Germany

Postby ravenhair on Mon Dec 19, 2005 3:21 pm

if you don't mind running another program exec dos2unix. This is exactly what it does.

Or in perl itself:
(took 30 seconds to find in google)

http://www.technocage.com/~caskey/dos2unix/


#!/usr/bin/perl -w
#
# A script to convert a number of java source
# files from dos line ending format to unix line format.
#
# WARNING: THIS SCRIPT DOES NOT CHECK FOR PRE-EXISTING
# FILES, USE WITH CAUTION.
#
# Usage: dos2unix <DIRECTORY>
#

$directory = shift @ARGV;
$directory = '.' unless $directory;
chdir( $directory ) || die "Unable to enter directory '$directory'.\n$!\n";

@files = <*.java>;
$| = 1;
$linesFixed = 0;
foreach( @files ) {
print "$_\t";
open(INPUT, "<$_");
rename( $_, "$_.bak") || die "Unable to rename $_\n$!\n";
open(OUTPUT, ">$_");
while(<INPUT>) {
if ( s/\r\n/\n/ ) {
$linesFixed++;
}
print OUTPUT;
}
} continue {
print "($linesFixed)\n";
$linesFixed = 0;
close INPUT;
close OUTPUT;
}
ravenhair
Regular
Regular
 
Posts: 80
Joined: Tue Nov 08, 2005 5:51 pm

Postby mm_freak on Sat Dec 24, 2005 8:42 am

De Kus wrote:generally you should transfer in binary mode, if not using human readable files :D. in that case the file syste will not try to convert to your local encoding :).


He is using HTTP, which doesn't care about line-feed encoding or binary vs. text mode. It just delivers what it gets. The best thing is to interpret the CR character properly, because it's not totally meaningless. Remember, a CR doesn't necessarily have to be followed by an LF.
I'm x^10 + x^8 + x^5 + x^4 + x^3 + 1, so don't mess with me!
mm_freak
Moderator
Moderator
 
Posts: 635
Joined: Sun Sep 11, 2005 12:29 pm
Location: Baden-Wuerttemberg (Germany)


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron