[PERL] 检测文件的换行符
时间:2010-03-03 来源:socyno
sub check_line_end_mode ()
{
my $file = shift;
my @ln = (0,0,0);
if ( -s $file and -T $file )
{
open (TEST, "$file") or return undef;
binmode(TEST);
my $stream = "\0" x 1024;
while ( read ( TEST, $stream, 1024 ) )
{
# windows
if ( $stream =~ /\015\012/o )
{
$ln[0] = 1;
}
# unix/linux like
if ( $stream =~ /[^\015]\012/o )
{
$ln[1] = 1;
}
# mac
if ( $stream =~ /\015[^\012]/o )
{
$ln[2] = 1;
}
}
close TEST;
}
elsif ( ! -e $file )
{
return undef;
}
return \@ln;
}
相关阅读 更多 +