Created
April 10, 2013 20:00
-
-
Save jdittmarCodeSnippets/5357930 to your computer and use it in GitHub Desktop.
Perl: lineBreakCheck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# line_break_check receives a file handle as its input and returns the new line character used in the file handle | |
sub line_break_check{ | |
my $file = shift; | |
local $/ = \1000; # read first 1000 bytes | |
local $_ = <$file>; # read | |
my ($newline) = /(\015\012?)/ ? $1 : "\012"; # Default to unix. | |
seek $file,0,0; # rewind to start of file | |
return $newline; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment