[Israel.pm] Talk: A natural flow for web apps

Ran Eilam eilara at cortext.co.il
Wed Mar 24 04:12:23 PST 2004


> > For those of us with no experience writing interactive perl scripts 
> > for the web, could you summarize why this is a problem (flow-wise)? 
> > What is it about the terminal-based prompt:
> >
> >   sub prompt {
> >      my $message = shift;
> >      print "$message\n";
> >      chomp(my $out = <>);

         ^^^^^^^^^^^^^^^^^^^^

As Yuval said, no way to block and wait for user input in web apps, from
inside user code. Unless I am proven wrong.

Your only option in web apps is to write a handler, that takes a request
and returns a response. Which is not how the natural flow of command
line apps works.

If you look at flow():

  sub flow_replace_product {
     my $old_name= prompt('Enter old product name:');
     delete_product_from_database($old_name);
 
     my $new_name= prompt('Enter new product name:');  
     add_product_to_database($new_name); 

     prompt('Thanx!');
  }

You can see it looks like web-CLIENT code, where prompt() is some web
service, which happens to be a user.

But it is actually web-SERVER code.

Programming clients is much easier, and you don't need to structure your
code in strange ways, or deal with state problems, like
storing/restoring session data and other useless stuff. This crud makes
up the bulk of our web apps.

> >      return $out;
> >   }
> >
> > that doesn't translate to web servers?
> 

Ran



More information about the Perl mailing list