in reply to Get HTML source code

Seems kind of silly to me to recreate the functionality that the browser provides for free, but here is a quick hack:

use strict; use warnings; use CGI qw(:standard); my $html = do {local $/;<DATA>}; if (param('view_source')) { $html = pre(escapeHTML($html)); } print header, $html; __DATA__ <html> <head> <title>view source example</title> </head> <body> <h1>view source example</h1> <a href="?view_source=1">view source</a> </body> </html>

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Get HTML source code
by jeffa (Bishop) on Nov 04, 2005 at 17:06 UTC

    Actually ... i think i like this one better:

    use strict; use warnings; use CGI qw(:standard); my $html = do {local $/;<DATA>}; my $mime = param('view_source') ? 'plain' : 'html'; print header("text/$mime"), $html; __DATA__ <html> <head> <title>view source example</title> </head> <body> <h1>view source example</h1> <a href="?view_source=1">view source</a> </body> </html>
    Let the browser handle the data as a plain text file, instead of having to escape HTML tags and wrap the results in pre tags.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)