- I'm basically using a PHP include to put the contents of a .txt file (in this case u_texas.txt) into an editable textarea. When the user makes changes to the textarea and submits it, the new text replaces the old text in the file.
- So far so good.
- The problem comes in when you go back and edit the file again. Every time, everywhere there is a new line, it adds another.
(e.g)
| starts | becomes | becomes |
|---|
1 2 3
|
1
2
3
|
1
2
3
|
and so on and so on.
I'm assuming this is caused by the \n characters being added on to each line of the STDIN, but I don't think chomp works in this case, at least I haven't been able to make it work.
This is the perl script which updates the file by recieving two form parameters; a file name, and the actual text that was in the text area.
#! c:\perl\bin\perl.exe -w
use strict;
use CGI;
my $query = CGI->new();
my @names = $query->param;
my $file_name = $query->param( $names[0] );
my $file_path = '../htdocs/safe/internship/u_texas.txt';
my $new_text = $query->param( $names[1]);
chomp(my $success = open OUT, ">$file_path");
# test for open omitted for space concerns
print OUT $new_text;
close OUT;
How does one perform a chomp on each line of text as it comes in, is that even possible, or am I just thinking about this the completely wrong way and if so, how should I be going about this process.
Thanks,
Chris (Boston,USA)
Edit by dws to add <code> tags
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.