|
-
Perl - strange control character appearing
I have a list of email addresses in one file, each on its own line.
I'm trying to output them to another file as a list separated by commas. Here is the code in question.
Code:
while (chomp($line = <MEMBER_LIST>))
{
print D_LIST $line . ',';
}
It gives me the email address separated by commas like I want, but it also throws in a "^M" after each address.
Like:
[email protected]^M,[email protected]^M,[email protected]^M,...
When I change that comma in the code to a newline character, the "^M" disappears. Any idea on why it's doing this?
AMD AthlonXP 2600+ Thoroughbred B @ 200x10.5
Shuttle AN35N nForce2 Ultra 400
2x512MB Kingston PC3200 (3-3-3)
ATI Radeon 9600 Pro
40GB WD ATA-100 8MB cache
Creative 12X DVD Drive
Memorex 52X CD-RW
Running Windows XP Pro
-
Nevermind, good old dos2unix fixed it.
AMD AthlonXP 2600+ Thoroughbred B @ 200x10.5
Shuttle AN35N nForce2 Ultra 400
2x512MB Kingston PC3200 (3-3-3)
ATI Radeon 9600 Pro
40GB WD ATA-100 8MB cache
Creative 12X DVD Drive
Memorex 52X CD-RW
Running Windows XP Pro
-
Ursus Arctos Moderatis
Yep, what you were seeing was a pirce of DOS/Windows newline characters. The character you were seeing represented as "^M" was actually the carriage return character of the ascii character set (decimal value of 13; often short-handed as \r)
Windows uses 2 characters to represent a newline (carriage return + line feed), while Unix only uses one character (line feed)
-
NullPointerException
Yep, and Macs (before they become Unix with OS X) just used the other one:
Windows: \r\n
Unix, Linux: \n
Mac: \r
One of the many annoyances of cross-platform work.
Open Source is free like a puppy is free.
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
Understanding Evolution
-
Ursus Arctos Moderatis
Oh wow really? I didn't know that about Macs...that's pretty funny. I never really respected them until OS X anyways 
Good to know though, thanks for the info rock - you learn something new every day.
-
Catfish
The Macs did that because the old Apple II line did the same thing, and they just picked it up as an Apple tradition or whatever. I don't think there was much standardization of text file formats back then. Anyone know what CP/M used?
If you transfer a file with FTP, and set the transfer type to ASCII, it will correct the end of line silliness, if both systems identify themselves correctly. Of course, if you transfer a file with FTP in ASCII mode that is not text, you'll really hose it up.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|