Stings - textareas in Perl...

Discussion in 'Perl Misc' started by joesplink, Mar 28, 2005.

  1. joesplink

    joesplink Guest

    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.. ??????
     
    joesplink, Mar 28, 2005
    #1
    1. Advertising

  2. "joesplink" <> 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.
     
    A. Sinan Unur, Mar 28, 2005
    #2
    1. Advertising

  3. joesplink

    joesplink Guest

    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???
     
    joesplink, Mar 28, 2005
    #3
  4. joesplink

    joesplink Guest

    Check... see that I must insert <br>s in the HTML.
     
    joesplink, Mar 28, 2005
    #4
  5. joesplink

    Guest

    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>/.
     
    , Mar 28, 2005
    #5
  6. joesplink

    Scott Bryce Guest

    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.
     
    Scott Bryce, Mar 28, 2005
    #6
  7. "joesplink" <> 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.
     
    A. Sinan Unur, Mar 28, 2005
    #7
  8. joesplink

    joesplink Guest

    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 ?????
     
    joesplink, Mar 28, 2005
    #8
  9. 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.
     
    Brian McCauley, Mar 28, 2005
    #9
  10. joesplink

    joesplink Guest

    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 ............
     
    joesplink, Mar 28, 2005
    #10
  11. joesplink

    Scott Bryce Guest

    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.
     
    Scott Bryce, Mar 28, 2005
    #11
  12. "joesplink" <> 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
     
    A. Sinan Unur, Mar 28, 2005
    #12
  13. joesplink

    joesplink Guest

    >>>>>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.
     
    joesplink, Mar 28, 2005
    #13
  14. joesplink

    joesplink Guest

    >>>>.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........
     
    joesplink, Mar 28, 2005
    #14
  15. joesplink

    Scott Bryce Guest

    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.
     
    Scott Bryce, Mar 28, 2005
    #15
  16. joesplink

    joesplink Guest

    >>>>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?
     
    joesplink, Mar 28, 2005
    #16
  17. 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.
     
    Brian McCauley, Mar 28, 2005
    #17
  18. "joesplink" <> 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
     
    A. Sinan Unur, Mar 28, 2005
    #18
  19. joesplink <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 28, 2005
    #19
  20. joesplink <> wrote:

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



    You should always enable warnings when developing Perl code!


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 28, 2005
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MacEgan
    Replies:
    2
    Views:
    355
    Andrew Thompson
    Dec 17, 2005
  2. MacEgan
    Replies:
    1
    Views:
    307
    IchBin
    Dec 17, 2005
  3. Jeff Thies

    Page test: expando textareas

    Jeff Thies, Jul 2, 2004, in forum: HTML
    Replies:
    4
    Views:
    397
    Blinky the Shark
    Jul 2, 2004
  4. Phil Cooperking

    Searching Stings with Arrays?

    Phil Cooperking, Dec 20, 2006, in forum: Ruby
    Replies:
    11
    Views:
    173
    William James
    Dec 25, 2006
  5. erobinson32

    perl: adding lines and replacing stings

    erobinson32, Mar 20, 2007, in forum: Perl Misc
    Replies:
    14
    Views:
    233
    Peter J. Holzer
    Mar 23, 2007
Loading...

Share This Page