Thread new lines werden nicht erkannt: new lines von windows unter os x (19 answers)
Opened by Gast at 2006-01-12 00:41

Strat
 2006-01-12 13:53
#61715 #61715
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
$/ = "\r\n"; fuer sowas zu verwenden ist gefaehrlich, weil \n je nach OS einen unterschiedlichen wert (naemlich den des OS) annimmt; besser murphy's weg waehlen, oder die einkommende Datei parsen und hoffen, dass es keine binaere Datei ist, z.B. auf die schnelle:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
my (@newLine) = &AnalyzeFileEol($infile);
my $newLine = join("", map { chr(hex($_)) } @newline;
local $/ = $newLine;

# ------------------------------------------------------------
sub AnalyzeFileEol {
my ($file) = shift;
my $eol = chr(10);

unless (open (FH, "<", $file)) {
die "Error: couldn't read file '$file': $!\n";
} # unless

my @chars = ();

while (defined (my $chr = getc(FH))) {
my $hex = sprintf("%02X", ord($chr));

if ($hex eq '0D') {
my $next = sprintf("%02X", ord(getc(FH)));

if ($next eq '0A') { close (FH);
print "Newline format: Dos: $hex $next\n";
return ($hex,$next);
} # if
else { close (FH);
print "Newline format: Mac: $hex\n";
return ($hex);
} # else
} # if
elsif ($hex eq '0A') { close (FH);
print "Newline format: Unix: $hex\n";
return ($hex);
} # elsif
} # while

die "Error: couldn't find out file format\n";

close (FH);
return;
} # AnalyzeFile
# ------------------------------------------------------------
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/

View full thread new lines werden nicht erkannt: new lines von windows unter os x