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.


In reply to Chomp doesn't seem to work by JaredHess

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.