Welcome to WebmasterWorld Guest from 23.20.241.155

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

appending to a text file

return lines

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

10+ Year Member



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";
close(DAT);

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.

thanks
Will

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

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



Just curious, what text editor are you using to view the file?
12:18 am on Oct 16, 2004 (gmt 0)

10+ Year Member



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

WebmasterWorld Senior Member 10+ Year Member



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


#!/usr/bin/perl

$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);

 

Featured Threads

Hot Threads This Week

Hot Threads This Month