Skip to content

Instantly share code, notes, and snippets.

@jdittmarCodeSnippets
Created April 10, 2013 20:00
Show Gist options
  • Save jdittmarCodeSnippets/5357930 to your computer and use it in GitHub Desktop.
Save jdittmarCodeSnippets/5357930 to your computer and use it in GitHub Desktop.
Perl: lineBreakCheck
# 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