in reply to Re: Detect line endings with CGI.pm upload
in thread Detect line endings with CGI.pm upload

Since we're using CGI.pm's upload function, $file is the file name on the client computer (in a scalar context) or a file-handle, but not the contents of the file itself. As such, $file =~ s/(\x0d?\x0a|\x0d)/\n/smg; is performing the substitution on the file name, not the contents of the file. But, its a good idea.

Manually setting $/ works but how do I detect what the line-ending should be so I can set $/ programmatically? perlvar is very explicit about it being a string, not a regex, so that's not an option. And the line-ending can be different for each of the three files being uploaded, even within a single CGI upload, so I cannot even do something based on the browser User-Agent.

Replies are listed 'Best First'.
Re^3: Detect line endings with CGI.pm upload
by gwadej (Chaplain) on Dec 28, 2008 at 21:01 UTC

    As I said, if we assumed the content of the file was in $file we could use that expression. If you want the content elsewhere, you can change the expression.

    If you are looking at determining the line ending while reading the data from the socket, you might want to look at the user agent identification in the HTTP_USER_AGENT environment variable. You should be able to determine the OS from there.

    G. Wade