Chinaunix首页 | 论坛 | 博客
  • 博客访问: 57783
  • 博文数量: 27
  • 博客积分: 2040
  • 博客等级: 大尉
  • 技术积分: 265
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-03 17:21
文章分类
文章存档

2010年(14)

2009年(13)

我的朋友

分类:

2010-03-03 23:58:52

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;
}
阅读(873) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~