in reply to Extra (\n)'s in the file I'm updating?

Couple of things to point out here. First of all, one of the lines in your code isn't doing what you think it's doing:
chomp(my $success = open OUT, ">$file_path"); # test for open omitted +for space concerns
open returns 1 on success and 0 on failure. What you're doing here is assigning the return value from open to the $success variable and then chomping it. For future reference always check the return value from open like this:
open(OUT, $file_path) || die "Couldn't open $file_path - $!\n";
Secondly, you are blindly accepting and using parameters without un-tainting them. If you don't know what this means, check out Ovid's CGI course, particularly the security section.

Lastly, to answer your original question, if the newlines are at the end you need to be chomping the $new_text variable prior to printing it to $file_path.

-- vek --

Replies are listed 'Best First'.
Re: Re: Extra (\n)'s in the file I'm updating?
by cdguitar01 (Monk) on Jan 11, 2003 at 19:08 UTC
    1st. Your right about the misplaced chomp. I seem to have posted a slightly older version of my code, that was simply an attempt. But it returned 1 just like it should have, so I put it back.

    2nd. Thanks for the open or die line, I hadn't been doing it like that before, my way took roughly 8 lines I think.

    3rd. I know about un-tainting from the first few chapters of the Ovid CGI course, but I never finished it because I moved to the O'Reilly Learning Perl book. I'm going to finish Ovid's once I'm done that book.
    No one can access this document from the outside world other then me, so for now I think I'm pretty safe.

    Thanks,
    Chris (boston,USA)