paul-s- has asked for the wisdom of the Perl Monks concerning the following question:
my $cr = chr(0x0d); my $lf = chr(0x0a); my $infile = "test.txt"; open (IN, "<$infile") or die "Couldn't open input file: $!"; my $first_line = <IN>; my ($line_text, $line_ending) = ($first_line =~ /(.*)(\015|\012|\015\0 +12)/); # detect line ending type if ($line_ending eq "$cr$lf") { print "Windows line ending\n"; } elsif ($line_ending eq "$lf") { print "UNIX line ending\n"; } elsif ($line_ending eq "$cr") { print "Mac line ending\n"; } else { print "Unknown line ending\n"; } close (IN);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to Detect Mixed File Line-Endings
by Corion (Patriarch) on Jan 17, 2014 at 12:28 UTC | |
by robby_dobby (Hermit) on Jan 18, 2014 at 13:15 UTC | |
|
Re: How to Detect Mixed File Line-Endings
by kcott (Archbishop) on Jan 17, 2014 at 20:49 UTC | |
|
Re: How to Detect Mixed File Line-Endings
by Anonymous Monk on Jan 17, 2014 at 13:34 UTC |