Re: Detecting line terminators in a CSV file
- From: dkasak@xxxxxxxxxxxxxxxxxxxx (Daniel Kasak)
- Date: Fri, 30 Jun 2006 15:04:31 +1000
John W. Krahn wrote:
Because when on Windows the CR LF pair is converted to the "\n"
newline character.
perldoc PerlIO
[snip]
:crlf
A layer that implements DOS/Windows like CRLF line endings. On
read converts pairs of CR,LF to a single "\n" newline character.
On write converts each "\n" to a CR,LF pair. Note that this layer
likes to be one of its kind: it silently ignores attempts to be
pushed into the layer stack more than once.
I see. Well that explains it.
Are you sure that you want to "fix" this?
Certain. I need to find the correct line terminator, and then tell MySQL
what it is.
perldoc -f binmode
binmode is what I was after - thanks :)
# Parse the 1st line of the import file and extract fieldnames
eval{
open SOURCE, $options->{source}
|| die "Failed to open file $options->{source}.\nIs the file
already open?";
};
if ( $@ ) {
Gtk2::Ex::Dialogs::ErrorMsg->new_and_run(
title => "Error opening file!",
text => $@
);
return FALSE;
}
You don't *have* to die if open doesn't work! And besides, using the high
precedence || operator means it won't die even if you wanted it to.
open SOURCE, '<', $options->{source} or do {
Gtk2::Ex::Dialogs::ErrorMsg->new_and_run(
title => 'Error opening file!',
text => $!
);
return FALSE;
};
It's working on my system as-is. I'll check out that precedence thing
when I get some spare time.
if ( substr( $fieldnames, length( $fieldnames ) -2, 2 ) eq "\r\n" ) {
You don't have to call the length() function, you can just use a negative number:
if ( substr( $fieldnames, -2, 2 ) eq "\r\n" ) {
Now *that* is useful. Thanks :)
--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@xxxxxxxxxxxxxxxxxxxx
website: http://www.nusconsulting.com.au
.
- Follow-Ups:
- Re: Detecting line terminators in a CSV file
- From: John W. Krahn
- Re: Detecting line terminators in a CSV file
- References:
- Detecting line terminators in a CSV file
- From: Daniel Kasak
- Re: Detecting line terminators in a CSV file
- From: John W. Krahn
- Detecting line terminators in a CSV file
- Prev by Date: Re: Detecting line terminators in a CSV file
- Next by Date: Variable inside regular expression
- Previous by thread: Re: Detecting line terminators in a CSV file
- Next by thread: Re: Detecting line terminators in a CSV file
- Index(es):
Relevant Pages
|