[25679] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7920 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 29 13:22:37 2005

Date: Tue, 29 Mar 2005 10:22:20 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 29 Mar 2005     Volume: 10 Number: 7920

Today's topics:
        Stings - textareas in Perl... <wdflannery@aol.com>
    Re: Stings - textareas in Perl... <1usa@llenroc.ude.invalid>
    Re: Stings - textareas in Perl... <wdflannery@aol.com>
    Re: Stings - textareas in Perl... <wdflannery@aol.com>
    Re: Stings - textareas in Perl... <nobull@mail.com>
    Re: Stings - textareas in Perl... <sbryce@scottbryce.com>
    Re: Stings - textareas in Perl... <1usa@llenroc.ude.invalid>
    Re: Stings - textareas in Perl... <wdflannery@aol.com>
    Re: Stings - textareas in Perl... <nobull@mail.com>
    Re: Stings - textareas in Perl... <wdflannery@aol.com>
    Re: Stings - textareas in Perl... <sbryce@scottbryce.com>
    Re: Stings - textareas in Perl... <1usa@llenroc.ude.invalid>
    Re: Stings - textareas in Perl... <wdflannery@aol.com>
    Re: Stings - textareas in Perl... <wdflannery@aol.com>
    Re: Stings - textareas in Perl... <sbryce@scottbryce.com>
    Re: Stings - textareas in Perl... <wdflannery@aol.com>
    Re: Stings - textareas in Perl... <nobull@mail.com>
    Re: Stings - textareas in Perl... <1usa@llenroc.ude.invalid>
    Re: Stings - textareas in Perl... <tadmc@augustmail.com>
    Re: Stings - textareas in Perl... <tadmc@augustmail.com>
    Re: Stings - textareas in Perl... <wdflannery@aol.com>
    Re: Stings - textareas in Perl... <dha@panix.com>
        Strange behaviour of nested sub <iketo2@netscape.net>
    Re: Strange behaviour of nested sub <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 27 Mar 2005 16:47:40 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Stings - textareas in Perl...
Message-Id: <1111970860.166658.282720@l41g2000cwc.googlegroups.com>

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.. ??????



------------------------------

Date: Mon, 28 Mar 2005 01:40:18 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Stings - textareas in Perl...
Message-Id: <Xns9626D24AA86ACasu1cornelledu@127.0.0.1>

"joesplink" <wdflannery@aol.com> wrote in news:1111970860.166658.282720
@l41g2000cwc.googlegroups.com:

> 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.


------------------------------

Date: 27 Mar 2005 19:54:27 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <1111982067.537847.266190@g14g2000cwa.googlegroups.com>

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???



------------------------------

Date: 27 Mar 2005 20:09:05 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <1111982945.105772.52280@f14g2000cwb.googlegroups.com>

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



------------------------------

Date: 27 Mar 2005 20:14:36 -0800
From: "nobull@mail.com" <nobull@mail.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <1111983276.853250.15780@g14g2000cwa.googlegroups.com>

Without any context joesplink wrote:

> 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>/.



------------------------------

Date: Sun, 27 Mar 2005 21:18:13 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <6bmdnaLXXroZGNrfRVn-pA@comcast.com>

joesplink wrote:

> 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.


------------------------------

Date: Mon, 28 Mar 2005 04:18:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Stings - textareas in Perl...
Message-Id: <Xns9626ED308FB08asu1cornelledu@127.0.0.1>

"joesplink" <wdflannery@aol.com> wrote in news:1111982945.105772.52280
@f14g2000cwb.googlegroups.com:

> 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.


------------------------------

Date: 27 Mar 2005 23:12:51 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <1111993971.333261.172320@g14g2000cwa.googlegroups.com>

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  ?????



------------------------------

Date: Mon, 28 Mar 2005 07:48:30 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <d28chh$nd0$1@sun3.bham.ac.uk>



joesplink wrote:

> 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.



------------------------------

Date: 28 Mar 2005 09:56:18 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <1112032577.993695.125290@z14g2000cwz.googlegroups.com>

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 ............



------------------------------

Date: Mon, 28 Mar 2005 11:39:45 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <E-adnWv-y4vt0tXfRVn-jg@comcast.com>

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.


------------------------------

Date: 28 Mar 2005 18:56:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Stings - textareas in Perl...
Message-Id: <Xns96278DCB027B4asu1cornelledu@132.236.56.8>

"joesplink" <wdflannery@aol.com> wrote in news:1112032577.993695.125290
@z14g2000cwz.googlegroups.com:

> 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
</TEXTAREA>";

> 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


------------------------------

Date: 28 Mar 2005 10:58:53 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <1112036333.393516.105640@z14g2000cwz.googlegroups.com>

>>>>>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.


>>>>Better not to (convert lf's to <br>s )anyhow.  If you want to be
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.



------------------------------

Date: 28 Mar 2005 11:51:36 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <1112039496.725238.43000@o13g2000cwo.googlegroups.com>

>>>>.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........



------------------------------

Date: Mon, 28 Mar 2005 13:54:53 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <H_6dnck368-A8tXfRVn-gA@comcast.com>

joesplink wrote:

> 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.


------------------------------

Date: 28 Mar 2005 13:10:30 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <1112044230.229786.121440@f14g2000cwb.googlegroups.com>

>>>>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?



------------------------------

Date: Mon, 28 Mar 2005 21:15:51 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <d29rrb$grs$1@sun3.bham.ac.uk>



joesplink wrote:
> 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.



------------------------------

Date: 28 Mar 2005 21:48:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Stings - textareas in Perl...
Message-Id: <Xns9627AAEEF1D2asu1cornelledu@132.236.56.8>

"joesplink" <wdflannery@aol.com> wrote in news:1112044230.229786.121440
@f14g2000cwb.googlegroups.com:

>>>>>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.

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


------------------------------

Date: Mon, 28 Mar 2005 15:57:22 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <slrnd4gve2.6bq.tadmc@magna.augustmail.com>

joesplink <wdflannery@aol.com> wrote:
>>>>>.And I thought I had asked you to *please* read the posting
> 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!


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 28 Mar 2005 15:59:29 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <slrnd4gvi1.6bq.tadmc@magna.augustmail.com>

joesplink <wdflannery@aol.com> wrote:

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


You should always enable warnings when developing Perl code!


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 28 Mar 2005 14:53:34 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <1112050414.613309.218100@l41g2000cwc.googlegroups.com>

>>>>This seems odd.

Indeed.  The second example is clearly bugged.... and why my strings
were growing.  However, the first example, which seems kosher to me,
causes me to lose trailing cr-lf's.  But, wait a minute..... I actually
prefer to get rid of those trailing cr-lf's anyhow....and have added a
little code to do it explicitly (courtesy of my Perl book)....so, I can
live with the first version....especially since I won't have to .....

>>>>>> examine the files with a binary editor. 

Thanks for your help.



------------------------------

Date: Mon, 28 Mar 2005 23:24:44 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <slrnd4h4hs.kdp.dha@panix2.panix.com>

On 2005-03-28, joesplink <wdflannery@aol.com> wrote:
>
> 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.

Not if you do it right. Look at the perlop page under $/.

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"You can lead a bigot to water, but if you don't tie him up, you can't
make him drown." - The Psychodots


------------------------------

Date: 24 Mar 2005 13:22:50 +0800
From: Isaac To <iketo2@netscape.net>
Subject: Strange behaviour of nested sub
Message-Id: <87y8cdsjmd.fsf@sinken.local.csis.hku.hk>

Hi,

I know this is not the right way to write programs (better use
closures), but still I would like to know the (design, technical,
dirty, or whatever) reason that the following program behave as it is
currently doing:

sub f1 {
    my $a = shift;
    sub f2 {
        print defined($a) ? "$a\n" : "undef\n";
    }
}
f2();  # print "undef"
f1(2);
f2();  # print "2"
f1(3);
f2();  # print "2" again

What this means is that f2 is defined before f1 runs, which is
expected because all sub's are defined at compile time.  But it also
means that the first call to f1 do something to f2, giving it a value
which will be used in all subsequent calls to f2, even if f1 is called
again later.  But... why?  Anywhere this behaviour is documented?

Regards,
Isaac.


------------------------------

Date: Sun, 27 Mar 2005 21:12:11 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Strange behaviour of nested sub
Message-Id: <d2778f$854$1@sun3.bham.ac.uk>



Isaac To wrote:

> Hi,
> 
> I know this is not the right way to write programs (better use
> closures), but still I would like to know the (design, technical,
> dirty, or whatever) reason that the following program behave as it is
> currently doing:

use diagnostics;

> 
> sub f1 {
>     my $a = shift;
>     sub f2 {
>         print defined($a) ? "$a\n" : "undef\n";
>     }
> }
> f2();  # print "undef"
> f1(2);
> f2();  # print "2"
> f1(3);
> f2();  # print "2" again
> 
> What this means is that f2 is defined before f1 runs, which is
> expected because all sub's are defined at compile time.  But it also
> means that the first call to f1 do something to f2, giving it a value
> which will be used in all subsequent calls to f2, even if f1 is called
> again later.

And of course, you get a warning telling you this has happened.

> Anywhere this behaviour is documented?

Yes, in the explaination of the warning you get.



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7920
***************************************


home help back first fref pref prev next nref lref last post