?
Solved

Problem writing to a file

Posted on 2000-01-04
8
Medium Priority
?
152 Views
Last Modified: 2010-03-05
When I write to a text file, it puts this character
 in place of a new line. Here is the script I'm using

$comments = $formdata{$key};

open(LOG,">>../clientaccess/password.txt")
  || &ErrorMessage;
foreach $key (sort keys(%formdata)) {
      print LOG "$formdata{$key}\n";
}
close(LOG);

Can someone help me get rid of it?
0
Comment
Question by:kch011099
8 Comments
 
LVL 3

Accepted Solution

by:
monas earned 200 total points
ID: 2323426
you might try to change \n to \r\n if you would like ms-dos style line-ends...
0
 
LVL 1

Expert Comment

by:olthoff
ID: 2323475
What character is it putting in?
0
 

Author Comment

by:kch011099
ID: 2323563
It is putting in a box-like character in place of a new line.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
LVL 1

Expert Comment

by:olthoff
ID: 2323608
I can't explain why it is adding the character, but you should be able to determine what character it is by:
print(ord(substr($line, startingpos,1)));

You can then strip that character from the file, or the line that you are writing.  
$formdata{$key} =~ s/\015//;

This removes the character (Octal value)
0
 

Expert Comment

by:Gaetano010400
ID: 2323939
This is kind a strange... What priviliges has been granted for execution of the script ? Most common is chmod 755.... I do not think this is going to help you out, just checking for at stupid error (Been there, done that) :)

/Gaetano
0
 

Author Comment

by:kch011099
ID: 2323965
I have all three boxes checked under execute, read, and write.

This is actually really strange because I am using this exact same script for another site and it works flawlessly.
0
 
LVL 1

Expert Comment

by:Kenny
ID: 2324711
As monas said, but in reverse, is you  use \r\n in NT, you will get that "illegal" character. Try switching between the 2 (\n and \r\n). I am very sure this is the problem cause I have had it before.
0
 

Author Comment

by:kch011099
ID: 2326305
Thank you everyone. The \r did the trick. It was the \n that was creating the box character, so I just got rid of it and used only \r.  
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question