Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: Tk vs browser-based applications

by kiat (Vicar)
on Jul 05, 2005 at 07:50 UTC ( [id://472376]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Tk vs browser-based applications
in thread Tk vs browser-based applications

Hm...I copy and pasted the code at GUI with HTTP::Daemon and then ran it by double-clicking on the script. The perl interpreter was started and all I could see was the Dos box with C:\perl\test\pizza.pl as the title.

Am I missing something?

Replies are listed 'Best First'.
Re^5: Tk vs browser-based applications
by Joost (Canon) on Jul 05, 2005 at 13:24 UTC
      I named the file pizza.pl. Where do I place it so that when I type http://localhost/pizza.pl, the server knows where to locate the file? With apache, I indicate the location of the files via the httpd.conf. Btw, the content of pizza.pl is as follows (from GUI with HTTP::Daemon):
      use strict; use HTTP::Daemon; use HTTP::Status; use CGI::Simple; sub res { HTTP::Response->new( RC_OK, OK => [ 'Content-Type' => 'text/html' ], shift ) } my %pages = ( index => sub { res qq[ <html><body> <h1>Pizza cost calculator</h1> <form method=post action=calc> Total cost: <input name=cost><br> Number of eaters: <input name=ppl><br> <input type=submit value=Submit> </form> </body></html> ]; }, calc => sub { my ($request) = @_; my $cgi = CGI::Simple->new( $request->content ); res sprintf q[ <html><body> <h1>Result</h1> Cost per eater: %.2f<br> <a href=index>Again!</a> </body></html> ], $cgi->param('cost') / $cgi->param('ppl'); }, ); my $daemon = HTTP::Daemon->new(LocalAddr => '127.0.0.1') or die; my $ppid = $$; if (my $pid = fork) { while (my $client = $daemon->accept) { while (my $request = $client->get_request) { my ($page) = $request->url->path =~ m[^/(\w+)$]; $page ||= 'index'; if (exists $pages{$page}) { $client->send_response( $pages{$page}->($request) ); } else { $client->send_error(RC_NOT_FOUND); } } $client->close; } } elsif (defined $pid) { my $url = $daemon->url; my @browsers = qw(firefox konqueror mozilla opera start); { @browsers or die "Couldn't start a browser."; my $b = shift @browsers; my $r = system("$b $url"); redo if $r; } } else { die "Couldn't fork!"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://472376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found