einerwitzen has asked for the wisdom of the Perl Monks concerning the following question:

I have a simple script that opens another script as if to edit it and shows it in a <textarea> tag. though sometimes when it shows a script that contains a <textarea> tag the browser reads the contained script as the pages code and closes the <textarea> and shows the remainder as page html.

you get what i'm sayin i think. what i'm wondering is if there is a way for me to when I open a .cgi to take it's contents into an array and filter it so that I can put the @array into a <textarea> tag to show through a browser without it messing anything up.

I'm new and don't know if a special command exists to do this, but i'm looking to see if there is.

anything helps thanks all!

Replies are listed 'Best First'.
Re: Show a script through a script?
by sauoq (Abbot) on Nov 02, 2002 at 01:50 UTC

    You need to escape your content by changing characters which would otherwise be interpretted as part of the HTML into their corresponding entities. If you are using the CGI module, it provides an escapeHTML() function. In your case, you might be able to get away with a couple quick regular expressions.

    my %entity = ( '<' => '&lt;', '>' => '&gt;', '&' => '&amp;', '"' => '&quot;', ); $text =~ s/([<>&"])/$entity{$1}/g;
    Update: Added entity for double quote.
    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Show a script through a script?
by BrowserUk (Patriarch) on Nov 02, 2002 at 01:48 UTC

    Passing the script you read in through the encode_entities() routine in the HTML::Enitites module should solve most of your problems.

    Its part of the my standard distribution, ie. AS build 633/perl 5.6.1


    Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy
      Its part of the standard distribution.

      Actually, it comes with HTML::Parser which is not a part of the standard distribution although I think it is included with ActiveState's distributions.

      -sauoq
      "My two cents aren't worth a dime.";