On May 3, 2012, at 10:19 AM, Mark Haney wrote:

> Okay, I can understand that.  Point me in the right direction for this.  I 
> don't really want to learn about steam engines if gas combustion engines are 
> 'the thing'.  I suppose that's been my point all along.

I'll point you to some additional resources below, but this seems like an 
appropriate time to say that, for what I understand your problem to be, a 
simple "classic" CGI using CGI.pm is a perfectly fine approach, particularly if 
this is something that's unlikely to get more complicated or if you need a 
stopgap solution while you start work on the more complicated replacement.

(I realize the irony behind saying that at this point in the conversation, and 
other people may disagree with me about the appropriateness of recommending 
CGI.pm. This is just my opinion.)

So, from what I understand, you have a Perl script that produces the output you 
want, and you want to stick that output inside an existing HTML page/template.

I would probably do something that looks a little bit like this:

  #! /path/to/your/perl

  use strict;
  use warnings;
  use CGI;
  use Template;

  my $q = CGI->new;
  print $q->headers();

  my $content = call_your_existing_code_that_gives_you_your_output();
  
  # n.b. modify your code to return everything as one long string. 

  my $t = Template->new( INCLUDE_PATH => 'path/to/directory/with/template' );
  $t->process( 'template_file.tt' , { content => $content };

  exit;

Don't run that yet. Take your existing template file, the one the PHP system 
uses, and in the spot where you want your content to be, put '[% content %]'. 

Now, try to run it. From the command line, not through a web browser. It should 
spit out a web page. See if it works -- it probably won't, I'm not actually 
testing this. See if you can figure out the error, spend 15-20 minutes on it, 
and if you're still stuck, reply back to the list. Include your code, the 
template file, and what error you get, and we'll go from there.

(Not trying to condescend with the above; apologies if I'm advocating stuff you 
already do or have tried.)

> As it is, please point me to how I can get perl to do CGI without CGI.pm.  
> I'm actually quite curious about how to do this as /why/ the move away from 
> the module in the first place.  (Although the latter is completely irrelevant 
> other than for my personal curiosity.)
> 
> Any resources out on the web about this will be greatly appreciated.


For "simple" web programming, I would suggest looking at either Dancer 
(<http://perldancer.org/>) or Mojolicious (<http://mojolicio.us/>).

For more complicated web programming, I would suggest looking at Catalyst 
(<http://www.catalystframework.org/>). 

The "why" is complex, but a big part of it is that for more complex web 
applications -- things that were traditionally done as a system of interlinked 
CGI.pm scripts -- it turns out to be a lot easier to develop and maintain 
things if you use one of the frameworks I mentioned above. They make things 
easier, they (gently) prevent you from (some ways of) shooting your foot off, 
and they're just generally less aggravating to work with than traditional 
CGI.pm CGIs. 

chrs,
john.


-- 
John SJ Anderson // geneh...@genehack.org



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to