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

73 my $out_file = "/var/www/html/shhabcam/LOGS/user_$assignment.html"; 374 375 if (-f $out_file) { 376 chmod 777, $out_file; 377 unlink $out_file or die "can't delete $out_file....$!"; 378 } 379 380 open (my $OUT, '>',"$out_file") or die "can't open $out_file....$! +"; 381 print $OUT $message;^M 382 close ($OUT); 383 384 # print $LOG "9\n"; 385 386 close ($LOG) if ($debug); 387 388 389 print "Content-type: text/html\n\n"; 390 print "<html><body><h3>$out_file created....</h3></body></html>\n" +;
I am constructing an HTML frrm a 'here' document. After I create the HTML I'd like to execute it.

Replies are listed 'Best First'.
Re: how can I execute an html file from Perl
by marto (Cardinal) on Oct 27, 2017 at 13:25 UTC

    HTML doesn't execute. Do you just want to display it? Consider using an actual framework, Mojolicious::Lite for example.

      HTML doesn't execute. Do you just want to display it? Consider using an actual framework, Mojolicious::Lite for example.

      Actual frameworks don't display HTML... :P

Re: how can I execute an html file from Perl
by Discipulus (Canon) on Oct 27, 2017 at 16:12 UTC
    You can point the browser of the end user to the file path as /path/to/bowser/browser /path/to/file.html or, for local only connection you can build up a server on the fly to serve the file to the end user browser, like using plackup

    plackup -p 5000 -MPlack::App::Directory -e 'Plack::App::Directory->new +({root => q{.}})->to_app'

    and point the user browser to http://127.0.0.1:5000 as suggested by YourMother in a thread where many other example of webserver oneliners are shown: Simple http server one-liner for some static files?

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: how can I execute an html file from Perl
by hippo (Archbishop) on Oct 27, 2017 at 14:57 UTC
    After I create the HTML I'd like to execute it.

    HTML isn't an executable format - it's markup (that's what the M stands for). I guess you mean print it? In which case, make your line 390 this:

    print $message;

      I am not stating my question adequately. I have constructed an HTML that consists of a number of inputs. Right now I am asking the user to enter the stated URL (in the browser) to display/execute this file. I would like to do this programactically.

        I think what you are now saying is that, given an absolute path on the filesystem, convert that to a URL and print it. In which case something like this (untested) should do:

        (my $url = $out_file) =~ s#$ENV{DOCUMENT_ROOT}#http://$ENV{SERVER_NAME +}#; print "Go to $url now for prizes!\n";

        Why not use a link ?

        print "Content-Type: text/html\n\n"; print qq!<html> <body><h3>$out_file created.... <a href="/shhabcam/LOGS/user_$assignment.html">here</a></h3> </body></html>\n!;
        poj