homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

appending to a text file
return lines

 10:23 pm on Oct 12, 2004 (gmt 0)

I am working on a project, trying to add lines to a text file. I am splitting the text file using javascript based on lines, so it is important that the added info is put on a new line. When i try to add to the file using perl, it only puts a box character and then ads the new info on the last line not creating the new line. this is the code that I am using to append to the file.

open(DAT, ">>".$data_file) ¦¦ die("not open file!");
print DAT "\n$last_name $first_name ,$year,$email";

as you can see I am using the \n . Is there something else that I should be using, or is there a different way to do that.




 11:42 pm on Oct 12, 2004 (gmt 0)

i was talking to people on yahoo chats, and figured out that the new line in windows is \r\n

i had used \n and \n\r and neither worked, but this one seemed to do it.


 3:04 pm on Oct 15, 2004 (gmt 0)

Just curious, what text editor are you using to view the file?


 12:18 am on Oct 16, 2004 (gmt 0)

notepad, on windows xp


 12:55 am on Oct 23, 2004 (gmt 0)

I don't see any problem with it. I ran the following code and it puts all the data on a new line:


$data_file = "foo.txt";
$last_name = "Doe"; $first_name = "Jon"; $year = 1963; $email = "jdoe\@foo\.com";
open (DAT, ">>$data_file") die ("not open file!");
print DAT "\n$last_name $first_name ,$year,$email";
close (DAT);

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved