On Wed, Jul 26, 2000 at 10:05:33AM -0500, David Steffen wrote: > > > I indeed read all those dest[0]'s from a file, and such the \n character > >> is in the end. > >> Solved it by removing the extra \n in the end of the To-command. (I, for > >> some reason, don't like that chomp command). > > > >If you ever have a $dest[0] without a newline at the end, I hope you won't > >have to ask the list why your headers are ending up on the same line... > > > >You should chomp $dest[0] and print the newline explicitly. > > I was more or less idlely following this thread, when it got me to > thinking. This is a case where you very much want to know the exact > state of something ($dest[0] in this case) so you know how to proceed. > > Chomp is good for dealing with 0 or 1 newlines, but what if there are > 43 newlines at the end of $dest[0]? > > I came up with two solutions that seem fairly robust to me: > > 1) Chomp until done: > for($l = chomp $dest[0]; $l; $l = chomp $dest[0]) { } Why a loop? { local $/ = ''; chomp $dest[0] } or $dest[0] =~ s/\n+$//; > The only problem with this is what if there are (multiple) newlines > embedded within $dest[0]? This may seem ridiculous, but consider the > case where $dest[0] ends with two newlines followed by a space? > Thus, my other solution is: > > $dest[0] =~ s/\n/ /g; tr/// is better for character to character translations. $dest[0] =~ tr/\n/ /; or even $dest[0] =~ tr/\n/ /s; > This assumes that completely eliminating a newline within a list of > multiple addresses might be bad, but that excess whitespace is not a > problem. I believe this to be true, but am not that much of a > sendmail expert. > > Comments? If $dest[0] is read in with $/ set to "\n", there cannot be more than one newline at the end of $dest[0], nor any embedded newlines. So, I would read in the value of $dest[0], and then immediately chomp() it, to make it clear that the two operations are related. Personally, I wouldn't worry about the other newline problems unless I changed how $dest[0] was filled. Ronald # ===== Want to unsubscribe from this list? # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org