Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Code + Results to HTML

by Anonymous Monk
on Feb 25, 2001 at 02:16 UTC ( #60680=sourcecode: print w/replies, xml ) Need Help??
Category: Miscellaneous
Author/Contact Info
Description: This program reads all *.pl files in a given directory and then outputs the script followed by the results to an html file. Any suggestions for improvements, or added robustness would be much appreciated.
foreach my $file(@files){
    my ($filestart)=$file=~/(.*?)\./;
    open INPUT, $file;
    my $source;
    while (<INPUT>){
    close INPUT;
    open FILE, ">$filestart.html";
    print "<HTML><BODY bgcolor=ffffff>\n";
    print "<PRE><CODE>";
    print $source;
    print "</CODE"."></PRE>";
    print "<B>Program results:</B>";
    print "<PRE>";
    eval $program;
    print "</PRE>";
    print "</BODY></HTML>";
    close FILE;
Replies are listed 'Best First'.
Re: Code + Results to HTML
by dws (Chancellor) on Feb 25, 2001 at 04:27 UTC
    If you insist on filtering the source yourself, rather than using routines in, you'll need to add:     $source=~s/&/&amp;/g;
Re: Code + Results to HTML
by TheoPetersen (Priest) on Feb 25, 2001 at 03:48 UTC
    Since you are going to stuff the whole file into a scalar anyway, let Perl do that for you:
    my $source; { open INPUT, $file; local $/ = undef; $source = <INPUT>; close INPUT; }
    You caught the need to escape the tag characters in the code, but there are some cases that will slip through. CGI's escapeHTML function can filter the whole file at once; I'm sure there are other implementations too.
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://60680]
[Tux]: you left the space in
[Tux]: and that \K is not required
[Tanktalus]: 11.31 is already 10 years old... you still need to support versions older than that? My condolences :)
[Eily]: meh, got confused. s/(?=\bis\b)/h/ will work better :)
[Eily]: \K keeps the thing on the left, not the right (IE, it's like look behind, not look ahead)
[Tux]: and 11.31 is still the last stable. We're moving all our customers to Linux (openSUSE and CentOS), but that takes a loooooooooooooooon g time
[LanX]: ehm ... I woke up my *boobs* ?
LanX where is the camera?
Tux => $HOME
[Eily]: you wrote boos instead of boss, and jedikaiti read that as boobs :)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2017-09-20 16:38 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (237 votes). Check out past polls.