Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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.
#!/usr/bin/perl
(@files)=<*.pl>;
foreach my $file(@files){
    my ($filestart)=$file=~/(.*?)\./;
    open INPUT, $file;
    my $source;
    while (<INPUT>){
       $source.=$_;
    }
    close INPUT;
    $program=$source;
    $source=~s/</&lt;/g;
    $source=~s/>/&gt;/g;
    open FILE, ">$filestart.html";
    *STDOUT=*FILE;
    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 CGI.pm, 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://60680]
help
Chatterbox?
[Marshall]: stevieb wish you well with water problems, my water was off all day Monday for repairs. Any more progress on .exe info problem?.
[stevieb]: Marshall: no. I commented on the thread yesterday. Visual Studio updates the tags ok, but corrupts the exe
[stevieb]: I advised the OP that a possible workaround would be to add a version function/flag that displays the required copyright/license info instead
[Marshall]: Darn! I'll look at the thread. Must not be updatinga byte count somewhere. The .exe format is a complex critter.
[stevieb]: that way, it's still "hard coded" into the exe at least, despite not being visible via Properties
[Marshall]: I also looked into PerlApp from Active State, but they don't sell their Dev Kit independent of a very expensive ($1,200) per year license anymore.
[Corion]: I would assume that the PE format hasn't changed that much since the days of yore, but it seems that I would be wrong in that assumption
[Marshall]: When I bought my copy 15+ years ago, it was just a couple hundred bucks.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2016-12-08 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (144 votes). Check out past polls.