JaredHess has asked for the wisdom of the Perl Monks concerning the following question:
My Perl and programmer newbie-ness keep me foul-fettered in the dungeons of code damnation! There is no release for my wretched soul! Alas! Perhaps the merciful monks can release me?
I can't figure out newlines between Windows and Unix platforms! Ahhhrgg! What a mess!
Here's the deal. Our web server is running Apache on a Unix system and my local machine is Windows XP Pro. I have a datafile of email addresses that I'm reading from on our web server. This list gets dynamically created from another script, pulling emails from our MYSQL database and putting them in the text file, one email per line.
I can create the list fine and I can read from it just fine in my current script. The only problem I run into is when I try to modify the list manually (maybe removing a few lines of emails) and then reuploading it to the server. That is when I become fettered. And there's a lot of wailing and gnashing of teeth because the darn chomp() function doesn't seem to work on my Windows modified .txt file. Then the rest of my script doesn't work.
I've created a crude workaround using the chop() function instead that has given my fevered brow at least some relief.
$lastchar = substr($email,-1); print p,$lastchar; if ($lastchar =~ /[a-zA-Z]/){ } else { print p, "Testing...Last char is not alphabetic"; chop($email); print p,"Testing...found newline, so we're chopping it!"; print p,"Testing...$email after chop " . length($email); }
But isn't there an easier way to set chomp to work with either Windows or Unix newlines? I don't know. I have searched the Good Book (Programming Perl) but could not find the answers.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Chomp doesn't seem to work
by Ovid (Cardinal) on Feb 03, 2005 at 00:59 UTC | |
|
Re: Chomp doesn't seem to work
by dave_the_m (Monsignor) on Feb 03, 2005 at 01:07 UTC | |
by halley (Prior) on Feb 03, 2005 at 15:45 UTC | |
|
Re: Chomp doesn't seem to work
by sh1tn (Priest) on Feb 03, 2005 at 01:08 UTC | |
|
Re: Chomp doesn't seem to work
by demerphq (Chancellor) on Feb 03, 2005 at 09:07 UTC | |
|
Re: Chomp doesn't seem to work
by Random_Walk (Prior) on Feb 03, 2005 at 12:26 UTC | |
|
Re: Chomp doesn't seem to work
by Anonymous Monk on Feb 03, 2005 at 22:48 UTC |