Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > editing perl script through TEXTAREA

Reply
Thread Tools

editing perl script through TEXTAREA

 
 
anita
Guest
Posts: n/a
 
      08-17-2004
Hello
I am trying to get to edit my perl scripts through a form. I'm loading
the perl script into the TEXTAREA, but the browser interprets the
stuff in the edit box. so if it happens to see another </TEXTAREa>
area in the text, it assumes it has found the end of the textarea and
the rest of my script is just spit out on the screen outside of the
textarea.
I can replace the > and < with HTML entities, while displaying and
whenthe user edits the fields, reinterpret the &entity back into > <
before saving.
My question is this- is there anything else I need to interpret before
I save ?
Like all those innumerable special chars in perl ?!

I realize this is strictly not a PERL question but would appreciate
any feedback. Especially if there are already some modules I can use
to do this sort of thing.
Thanks
anita
 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      08-17-2004
On Tue, 17 Aug 2004 14:03:57 -0700, anita wrote:
> I am trying to get to edit my perl scripts through a form. I'm loading
> the perl script into the TEXTAREA, but the browser interprets the stuff
> in the edit box. so if it happens to see another </TEXTAREa> area in the
> text, it assumes it has found the end of the textarea and the rest of my
> script is just spit out on the screen outside of the textarea.


Check out the HTML::Entities module. It will let you encode any "special"
characters to HTML.


--
Tore Aursand <(E-Mail Removed)>
"The road to hell is full of good intentions." (Bruce Dickinson)
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      08-17-2004
anita wrote:
> I am trying to get to edit my perl scripts through a form. I'm
> loading the perl script into the TEXTAREA, but the browser
> interprets the stuff in the edit box. so if it happens to see
> another </TEXTAREa> area in the text, it assumes it has found the
> end of the textarea and the rest of my script is just spit out on
> the screen outside of the textarea.
> I can replace the > and < with HTML entities, while displaying and
> whenthe user edits the fields, reinterpret the &entity back into >
> < before saving.


If you save before converting to HTML entities, you don't need to
convert those characters back.

> My question is this- is there anything else I need to interpret
> before I save ?
> Like all those innumerable special chars in perl ?!
>
> I realize this is strictly not a PERL question but would appreciate
> any feedback. Especially if there are already some modules I can
> use to do this sort of thing.


I'm not sure if there is a *need* to convert any other characters for
this limited purpose. However, this is a function I'm using:

sub entify {
my $ref = defined wantarray ? [ @_ ] : \@_;
for ( grep defined, @$ref ) {
s/&/&amp;/g;
s/"/&quot;/g;
s/</&lt;/g;
s/>/&gt;/g;
}
@$ref > 1 ? @$ref : $$ref[0]
}

Besides < and > it converts & and ".

There are also modules, of course, such as HTML::Entities, or you can
use the escapeHTML() function in CGI.pm.

HTH

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      08-17-2004
anita <(E-Mail Removed)> wrote:

> I am trying to get to edit my perl scripts through a form.



Why are you trying to get to edit your perl scripts through a form?

I am sensing an X-Y problem here...


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
anita
Guest
Posts: n/a
 
      08-18-2004
Lets just say I am editing some file, any file through the form... Not
necessarily a perl script. That- is a good example because it tends to
have a lot of special characters.
One other person suggested that I save before converting. I am not
sure what was meant by that.

From what I understand, my file has to be processed to replace all the
special HTML chars before display (so browser wont complain) and once
the user edits and tries to save it through the form, it has to be
stripped off the special entities, so it can be saved...

I will look into the HTML module.
> I am sensing an X-Y problem here...


I dont get it. What do you mean X-y problem ?
Thanks
 
Reply With Quote
 
anita
Guest
Posts: n/a
 
      08-18-2004
Lets just say I am editing some file, any file through the form... Not
necessarily a perl script. That- is a good example because it tends to
have a lot of special characters.
One other person suggested that I save before converting. I am not
sure what was meant by that.

From what I understand, my file has to be processed to replace all the
special HTML chars before display (so browser wont complain) and once
the user edits and tries to save it through the form, it has to be
stripped off the special entities, so it can be saved...

I will look into the HTML module.
> I am sensing an X-Y problem here...


I dont get it. What do you mean X-y problem ?
Thanks
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      08-18-2004
anita <(E-Mail Removed)> wrote:
> Lets just say I am editing some file, any file through the form...


>> I am sensing an X-Y problem here...

>
> I dont get it. What do you mean X-y problem ?



An XY problem is when you want to do X, but you ask how to do Y
instead, because you've decided that Y is the best way to accomplish X.


If you tell us why you think you want to edit programs in a browser,
then maybe we could suggest a better or easier alternative...


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
gnari
Guest
Posts: n/a
 
      08-18-2004
"Abigail" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed).. .
> anita ((E-Mail Removed)) wrote on September MCMXCIII in
> <URL:news:(E-Mail Removed) le.com>:
> --
> -- I am trying to get to edit my perl scripts through a form. I'm loading
>
>
> That sounds about as cumbersome and useful as eating soup through
> the keyhole of a door.


naw, you just use one of those bendy straws.

gnari




 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      08-18-2004
anita wrote:
> One other person suggested that I save before converting. I am not
> sure what was meant by that.


Suppose I'm that "other person". Post your code if you want me to
explain further.

> From what I understand, my file has to be processed to replace all
> the special HTML chars before display (so browser wont complain)


No, your file does not need to be processed. Your *data*, whereever it
come from, need to be processed before display.

> and once the user edits and tries to save it through the form, it
> has to be stripped off the special entities, so it can be saved...


No. The form takes care of that.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Tore Aursand
Guest
Posts: n/a
 
      08-18-2004
On Tue, 17 Aug 2004 20:46:05 -0700, anita wrote:
> Lets just say I am editing some file, any file through the form... Not
> necessarily a perl script. That- is a good example because it tends to
> have a lot of special characters.


You still want to use the HTML::Entities module. Here's an example for
you to (hopefully) learn from (untested):

#!/usr/bin/perl
#
use strict;
use warnings;
use HTML::Entities qw( encode_entities );

my $data = 'whatever'; # This is very you read the data you want to
# convert to HTML from a file or something.

$data = encode_entities( $data ); # Convert any "special" characters
# to HTML entities.

# Do whatever you need to do with the converted $data variable.


--
Tore Aursand <(E-Mail Removed)>
"When you love someone, all your saved-up wishes start coming out."
(Elizabeth Bowen)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add </textarea> within <textarea> tags? frank.moens@gmail.com Javascript 1 07-04-2007 04:00 PM
Textarea Inside of a textarea wperry1@gmail.com ASP General 6 02-05-2006 08:00 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
Removing carriage returns from <textarea></textarea> input Augustus ASP General 1 09-10-2003 04:55 AM
How to make Perl Script "POST" call from another Perl Script??? Wet Basement Perl 1 07-15-2003 10:25 PM



Advertisments