Stings - textareas in Perl...

J

joesplink

1. Is there a free script for putting up a textarea with controls for
fort/size/color...etc. for the entered text.. ????

2. A TEXTAREA control can return a string with newlines (?) in it,
but, when I print the string the newlines are supressed and everything
prints on a single line.... what is going on? .... how do I get a
string from a textarea and print it without supressing the
newlines....and... how can I save it to a file...as a single line....so
that it will read as one line.. ??????
 
A

A. Sinan Unur

Subject: Stings - textareas in Perl...

There are no textareas in Perl.
1. Is there a free script for putting up a textarea with controls for
fort/size/color...etc. for the entered text.. ????

How textareas are rendered is a user agent feature. I am guessing this
question would be more appropriate in a Javascript/HTML/CSS group.
2. A TEXTAREA control can return a string with newlines (?) in it,
but, when I print the string the newlines are supressed and everything
prints on a single line.... what is going on? .... how do I get a
string from a textarea and print it without supressing the
newlines....and... how can I save it to a file...as a single line....so
that it will read as one line.. ??????

I don't know if there is a Perl question in there. This is more a question
about CGI, HTML, and user agent interaction.

Sinan.
 
J

joesplink

I'll try to be less vague. My PERL script gets input from a TEXTAREA
that contains newlines. I can replace /\n/#/g and print the result and
see the #'s where I expect them. However, if I print the string (not
replacing the \n's) by including it in an HTML document I send to the
browser, it prints as a single line. How can I get it to print showing
the newlines as originally entered in the TEXTAREA???
 
N

nobull

Without said:
I'll try to be less vague.

Please give context (quoted material) in your follow-up posts.

Also try to partition your problem - work out what is the question that
you are asking, and what is just the context in which the question
arrose.
My PERL script gets input from a TEXTAREA
that contains newlines. I can replace /\n/#/g and print the result and
see the #'s where I expect them. However, if I print the string (not
replacing the \n's) by including it in an HTML document I send to the
browser, it prints as a single line. How can I get it to print showing
the newlines as originally entered in the TEXTAREA???

It would appear that the question you are asking is how to represent a
newline in HTML.

This has nothing to do with Perl - it is a pure HTML question.

The representation of newline in HTML is <br>.

Note also that the '<' and '&' must also be represented specially in
HTML so convert your string with escapeHTML before you s/\n/<br>/.
 
S

Scott Bryce

joesplink said:
I'll try to be less vague. My PERL script gets input from a TEXTAREA
that contains newlines. I can replace /\n/#/g and print the result and
see the #'s where I expect them. However, if I print the string (not
replacing the \n's) by including it in an HTML document I send to the
browser, it prints as a single line. How can I get it to print showing
the newlines as originally entered in the TEXTAREA???

This is an HTML issue, not a Perl issue.

s(\n)(<br />)g;

might be a Perl way to solve your HTML problem.
 
A

A. Sinan Unur

Check... see that I must insert <br>s in the HTML.

It sounds like you are talking to yourself.

Please quote an appropriate amount of context when replying.

Please note that whatever your problem was, it had nothing to do with
Perl.

Sinan.
 
J

joesplink

Hmmmm, curiouser and curiouser ... I have tried s/\n/<br>/g.... and the
string prints OK as HTML..... however, I save the string to disc with
the <br>s.... and convert the <br>s back to \n's when I want to put it
back in the TEXTAREA for further editing.... and my stings are
growing....

I note that if I type A in the TEXTAREA, the length of the string
returned is 1, whereas if I type A<enter>, i.e, 2 keystrokes, A and
<enter>, the length of the string returned is 3..... not 2..... so the
TEXTAREA is returning more than the \n for an <enter>.....and my PERL
is not yet up to telling me what the other character is ...... what is
it ????? linefeed ? \l ?????
 
B

Brian McCauley

joesplink said:
Hmmmm, curiouser and curiouser ... I have tried s/\n/<br>/g.... and the
string prints OK as HTML..... however, I save the string to disc with
the <br>s.... and convert the <br>s back to \n's when I want to put it
back in the TEXTAREA for further editing.... and my stings are
growing....

I note that if I type A in the TEXTAREA, the length of the string
returned is 1, whereas if I type A<enter>, i.e, 2 keystrokes, A and
<enter>, the length of the string returned is 3..... not 2..... so the
TEXTAREA is returning more than the \n for an <enter>

Carriage return.

HTML form text areas delimit lines with CR-LF.

Why it should grow when you change the LF to <br> and back is not
obvious to me. How are you writing it out to disk and reading it back?

Better not to anyhow. If you want to be able to edit the text then
store it as entered. Transform it when you come to display it.

And don't forget the escapeHTML.
 
J

joesplink

Yes, TEXTAREA is returning cr-lf for new lines... so, I thought my
problems were over.... but nooooo....

if, in my Perl routine I code

my $Field = "A\r\n\B";

and then generate a form

print ........."<TEXTAREA.......>$Field</TEXTAREA>

and then click on Done without editing, the TEXTAREA will return
"A\r\nB"

However, if I code
my $Field = "A\r\n\B\r\n";

I still only get back "A\r\nB", i.e. I"ve lost my trailing cr-lf.


On the other hand....... if I generate the form with

print <TEXTAREA.......>$Field
</TEXTAREA>

then a cr-lf will be appended to the value of $Field......


As a geek I know likes to say ..... it's very cornfusing......

Oy Vey ............
 
S

Scott Bryce

joesplink wrote:

<HTML/CGI problem snipped>

Perhaps you should be posting your HTML problems on an HTML newsgroup.
If you feel that you have a Perl problem, please read the posting
guidelines for this newsgroup, then post a short but complete script
that demonstrates the problem.
 
A

A. Sinan Unur

Yes, TEXTAREA is returning cr-lf for new lines... so, I thought my
problems were over.... but nooooo....

And I thought I had asked you to *please* read the posting guidelines for
this group. They contain invaluable information on how to

1. help yourself
2. help others help you
if, in my Perl routine I code

my $Field = "A\r\n\B";

and then generate a form

print ........."<TEXTAREA.......>$Field</TEXTAREA>

That is not Perl code.
and then click on Done without editing,

Click on Done where? (Please do not feel compelled to answer this
question).
On the other hand....... if I generate the form with

print <TEXTAREA.......>$Field
</TEXTAREA>

Assuming that was

print "<TEXTAREA>$Field
then a cr-lf will be appended to the value of $Field......

you are forgetting about the embedded newline.
As a geek I know likes to say ..... it's very cornfusing......

Oy Vey ............

Double oy vey from here. This is a Perl forum. It is neither a CGI nor an
HTML forum. Learning the appropriate forum to post your questions will
help you find useful answers faster.

Sinan
 
J

joesplink

Why it should grow when you change the LF to <br> and back is not
obvious to me.

Ya, that wasn't the problem ... that one is solved.

able to edit the text then
store it as entered. Transform it when you come to display it.

The reason I convert the lf's before writing to disc is because I want
to read the disk file with

my @array = <DATAFILE>;

and if I write the string with embedded lf's it will come back as
multiple array elements.
 
J

joesplink

.And I thought I had asked you to *please* read the posting
guidelines for
this group.

I'm a renegade.

And it does seem to me that there are Perl issues.....to be
specific....if I code

my $Field="A\r\l";

print "......<TEXTAREA.....>$Field</TEXTAREA>...................";

and then submit the displayed TEXTAREA it will return "A" only.

Even if I set my $Field="A\r\l\r\l" I still get back only "A"......

However, if I code....

my $Field="A";

print "......<TEXTAREA.....>$Field
</TEXTAREA>...................";

then I'll get back ... "A\r\l"

So, (at least part of) the problem is I don't know exactly what string
Perl is sending to the browser in the above instances....in particular,
how does what is sent in the last example differ from what is sent in
the first ??????

Once I know that .... I can proceed to the HTML group........
 
S

Scott Bryce

joesplink said:
I'm a renegade.

If you don't play by the rules, you will be killfiled by many of the
regulars here.
And it does seem to me that there are Perl issues.

No. Your question has nothing to do with Perl. If you wrote your CGI in
any other language, you would still have the same problem.
 
J

joesplink

No. Your question has nothing to do with Perl. If you wrote your
CGI in
any other language, you would still have the same problem.

I've presented 2 different Perl snippets..... claiming that they
generate different output to the server.....and asking, in effect, "Why
don't these 2 snippets send the same output to the server?".........or,
more specifcally ... "exactly what do these scripts send to the
server?"......

That's not a Perl question?
 
B

Brian McCauley

joesplink said:
Yes, TEXTAREA is returning cr-lf for new lines... so, I thought my
problems were over.... but nooooo....

if, in my Perl routine I code

my $Field = "A\r\n\B";

and then generate a form

print ........."<TEXTAREA.......>$Field</TEXTAREA>

and then click on Done without editing, the TEXTAREA will return
"A\r\nB"

However, if I code
my $Field = "A\r\n\B\r\n";

I still only get back "A\r\nB", i.e. I"ve lost my trailing cr-lf.


On the other hand....... if I generate the form with

print <TEXTAREA.......>$Field
</TEXTAREA>

then a cr-lf will be appended to the value of $Field......

This seems odd. The second example will possibly terminate the string
with only \n. But if anything I'd expect the opposite.

I suggest you run these two examples - save the resulting pages from the
browser and examine the files with a binary editor.
 
A

A. Sinan Unur

Please provide attributions when you reply.
I've presented 2 different Perl snippets..... claiming that they
generate different output to the server.....and asking, in effect, "Why
don't these 2 snippets send the same output to the server?".........or,
more specifcally ... "exactly what do these scripts send to the
server?"......

That's not a Perl question?

No, because the answer would be the same regardless of the language being
used.

Sinan
 
T

Tad McClellan

joesplink said:
guidelines for
this group.

I'm a renegade.


You can call it that if you like, but most people here will
read it as "I'm anti-social".

Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top