You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Hemond, Steve" <SH...@SMURFIT.com> on 2004/01/27 21:45:17 UTC

RE : Handlers vs Perl scripts

Could anyone explain me why having perl files like :

printf ("<HTML> blahblahb");
printf ("My name is %s",$name);

Is a wrong idea? :-)

Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestières
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
shemond@smurfit.com 



 > -----Original Message-----
 > From: David R. Baird [mailto:dave@zerofive.co.uk] 
 > Sent: Tuesday, January 27, 2004 12:13 PM
 > To: modperl@perl.apache.org
 > Subject: Re: Handlers vs Perl scripts 
 > 
 > 
 > Really, everything you are trying to do is made so much easier in 
 > Mason. Have you tried the Mason list for help with your bugs? 
 > 
 > Embedding html inside perl scripts is not the way to go - it'll 
 > get very unwieldy very quickly. 
 > 
 > If you put most of your functions into modules (eg for db 
 > access), then you can load the modules into your Mason web pages, 
 > which minimises the amount of perl code in your html. It also 
 > makes it much easier to debug - you can load the module into a 
 > test script and check the return values of each function.
 > 
 > Mason makes handling query strings a breeze too. 
 > 
 > d.
 > 
 > On 27 Jan 2004 at 10:54, Hemond, Steve wrote:
 > 
 > > Hi again!
 > > 
 > > After taking too much time at debugging my Mason bugs 
 > (unsuccessfully) 
 > > , I decided to abandon the idea of embedding perl code in my web 
 > > pages.
 > > 
 > > I will setup ONE handler that will only generate a header 
 > and a footer 
 > > on each webpage. I'm not at ease with the idea of having a 
 > bunch of 
 > > handlers for every dynamic operation and to restart Apache 
 > everytime I 
 > > setup a new handler, so I will limit myself to my header/footer 
 > > handler and do the rest in perl scripts.
 > > 
 > > My question is : Coding perl scripts like this :
 > > 
 > > #!/usr/bin/perl
 > > 
 > > print ("<html><head> ...")
 > > etc...
 > > 
 > > is also taking profit of mod_perl? I mean... is that still 
 > a good way 
 > > to build mod_perl websites?
 > > 
 > > Instead of embedding perl code in html files to generate 
 > stuff from a 
 > > database, I would just have to write an entire perl file that will 
 > > print the html code (like the example I've shown above) and do the 
 > > manipulations on the database at the same time. I'm just 
 > wondering if 
 > > this is a good idea, or if I am missing the features of 
 > mod_perl at 
 > > all.
 > > 
 > > If I go with this idea, is there any documentation that 
 > shows how to 
 > > handle query strings from a simple perl file?
 > > 
 > > Another question : I would need a sub to insert stuff in 
 > the database, 
 > > another to extract stuff, another to show date/time, etc. 
 > Should I put 
 > > these functions in a simple module that I will include in 
 > every perl 
 > > script?
 > > 
 > > Thanks a lot for your help,
 > > 
 > > Best regards,
 > > 
 > > Steve Hemond
 > > Programmeur Analyste / Analyst Programmer
 > > Smurfit-Stone, Ressources Forestieres
 > > La Tuque, P.Q.
 > > Tel.: (819) 676-8100 X2833
 > > shemond@smurfit.com
 > > 
 > > 
 > > --
 > > Reporting bugs: http://perl.apache.org/bugs/
 > > Mail list info: http://perl.apache.org/maillist/modperl.html
 > > List etiquette: 
 > http://perl.apache.org/maillist/email- > etiquette.html
 > 
 > 
 > 
 > -- 
 > 
 > Dr. David R. Baird
 > ZeroFive Web 
 > Design
 > dave@zerofive.co.uk
 > http://www.zerofive.co.uk
 > 
 > -- 
 > Reporting bugs: http://perl.apache.org/bugs/
 > Mail list info: http://perl.apache.org/maillist/modperl.html
 > List etiquette: http://perl.apache.org/maillist/email-etiquette.html
 > 
 > 

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Handlers vs Perl scripts

Posted by Garth Webb <ga...@zappos.com>.
On Tue, 2004-01-27 at 12:45, Hemond, Steve wrote:
> Could anyone explain me why having perl files like :
> 
> printf ("<HTML> blahblahb");
> printf ("My name is %s",$name);
> 
> Is a wrong idea? :-)

For one, most HTML pages will probably contain more than one tag and
more than two lines of text.  Take this bit of code from cvsweb.cgi (a
very handy CVS viewer) which contains all the code and all the HTML in
one file:

======

$infocols++;
printf '<th style="text-align: left; background-color: %s">',
  $byrev ? $columnHeaderColorSorted :
  $columnHeaderColorDefault;

if ($byrev) {
    print 'Rev.';
} else {
    print &link(
		'Rev.',
		sprintf(
			'./%s#dirlist',
			&toggleQuery("sortby", "rev")
		       )
	       );
}
print "</th>\n";
$infocols++;
printf '<th style="text-align: left; background-color: %s">',
  $bydate ? $columnHeaderColorSorted :
  $columnHeaderColorDefault;

if ($bydate) {
    print 'Age';
} else {
    print &link(
		'Age',
		sprintf(
			'./%s#dirlist',
			&toggleQuery("sortby", "date")
		       )
	       );
}
print "</th>\n";


====

Now, can you tell me how many columns of a table this will construct at
a glance?  Note that this only outputs a single row.  Can you imaging
how much more code exists to output the rest of the table?

What happens if the code works perfectly, but you want to change the
layout?  The Perl must be reworked as much (and sometimes more) as the
HTML.  Not only is it difficult and tedious to find the right HTML when
its completely interspersed with Perl, but you run the risk of breaking
your already working Perl code, or worst introducing a hidden bug.

Additionally if you have a programmer and a designer, mixing HTML and
Perl means that your designer has to be a decent coder and the coder has
to be a decent designer.

That's why its a bad idea! :)

-- 

 |- Garth Webb       -|
 |- garth@zappos.com -|

RE: RE : Handlers vs Perl scripts

Posted by Gary Barnett <gb...@gb-cs.com>.
Look for quoted strings in the docs.

i.e.
my $my_name = "Blah";
print qq(<HTML><BODY><IMG SRC="test.jpg"></BODY></HTML>\n<br>My name is
$my_name);

Note that escaping the " character is not necessary.

--Gary


-----Original Message-----
From: Hemond, Steve [mailto:SHEMOND@SMURFIT.com] 
Sent: Tuesday, January 27, 2004 12:45 PM
To: modperl@perl.apache.org
Subject: RE : Handlers vs Perl scripts 


Could anyone explain me why having perl files like :

printf ("<HTML> blahblahb");
printf ("My name is %s",$name);

Is a wrong idea? :-)

Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestières
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
shemond@smurfit.com 



 > -----Original Message-----
 > From: David R. Baird [mailto:dave@zerofive.co.uk] 
 > Sent: Tuesday, January 27, 2004 12:13 PM
 > To: modperl@perl.apache.org
 > Subject: Re: Handlers vs Perl scripts 
 > 
 > 
 > Really, everything you are trying to do is made so much easier in 
 > Mason. Have you tried the Mason list for help with your bugs? 
 > 
 > Embedding html inside perl scripts is not the way to go - it'll 
 > get very unwieldy very quickly. 
 > 
 > If you put most of your functions into modules (eg for db 
 > access), then you can load the modules into your Mason web pages, 
 > which minimises the amount of perl code in your html. It also 
 > makes it much easier to debug - you can load the module into a 
 > test script and check the return values of each function.
 > 
 > Mason makes handling query strings a breeze too. 
 > 
 > d.
 > 
 > On 27 Jan 2004 at 10:54, Hemond, Steve wrote:
 > 
 > > Hi again!
 > > 
 > > After taking too much time at debugging my Mason bugs 
 > (unsuccessfully) 
 > > , I decided to abandon the idea of embedding perl code in my web 
 > > pages.
 > > 
 > > I will setup ONE handler that will only generate a header 
 > and a footer 
 > > on each webpage. I'm not at ease with the idea of having a 
 > bunch of 
 > > handlers for every dynamic operation and to restart Apache 
 > everytime I 
 > > setup a new handler, so I will limit myself to my header/footer 
 > > handler and do the rest in perl scripts.
 > > 
 > > My question is : Coding perl scripts like this :
 > > 
 > > #!/usr/bin/perl
 > > 
 > > print ("<html><head> ...")
 > > etc...
 > > 
 > > is also taking profit of mod_perl? I mean... is that still 
 > a good way 
 > > to build mod_perl websites?
 > > 
 > > Instead of embedding perl code in html files to generate 
 > stuff from a 
 > > database, I would just have to write an entire perl file that will 
 > > print the html code (like the example I've shown above) and do the 
 > > manipulations on the database at the same time. I'm just 
 > wondering if 
 > > this is a good idea, or if I am missing the features of 
 > mod_perl at 
 > > all.
 > > 
 > > If I go with this idea, is there any documentation that 
 > shows how to 
 > > handle query strings from a simple perl file?
 > > 
 > > Another question : I would need a sub to insert stuff in 
 > the database, 
 > > another to extract stuff, another to show date/time, etc. 
 > Should I put 
 > > these functions in a simple module that I will include in 
 > every perl 
 > > script?
 > > 
 > > Thanks a lot for your help,
 > > 
 > > Best regards,
 > > 
 > > Steve Hemond
 > > Programmeur Analyste / Analyst Programmer
 > > Smurfit-Stone, Ressources Forestieres
 > > La Tuque, P.Q.
 > > Tel.: (819) 676-8100 X2833
 > > shemond@smurfit.com
 > > 
 > > 
 > > --
 > > Reporting bugs: http://perl.apache.org/bugs/
 > > Mail list info: http://perl.apache.org/maillist/modperl.html
 > > List etiquette: 
 > http://perl.apache.org/maillist/email- > etiquette.html
 > 
 > 
 > 
 > -- 
 > 
 > Dr. David R. Baird
 > ZeroFive Web 
 > Design
 > dave@zerofive.co.uk
 > http://www.zerofive.co.uk
 > 
 > -- 
 > Reporting bugs: http://perl.apache.org/bugs/
 > Mail list info: http://perl.apache.org/maillist/modperl.html
 > List etiquette: http://perl.apache.org/maillist/email-etiquette.html
 > 
 > 

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


RE : Handlers vs Perl scripts

Posted by "David R. Baird" <da...@zerofive.co.uk>.
On 27 Jan 2004 at 15:45, Hemond, Steve wrote:

> Could anyone explain me why having perl files like :
> 
> printf ("<HTML> blahblahb");
> printf ("My name is %s",$name);
> 
> Is a wrong idea? :-)

Because that's not all you will have. You will have 

printf ("<HTML> blahblahb");
printf ("My name is %s",$name);

+ 763 more printf statements. With scattered logic added among 
those printf statements. And a major nightmare when you want to 
change the look of the site. And just how do you find the source 
of that obscure HTML error that you just discovered in IE 5.0? 
And when you fix that html bug - you'll need to restart the 
server to load the new version of your handler. 

Presentation and logic are two different things, and the more you 
can keep them apart, the easier your life will be. 

d.


-- 
Dr. David R. Baird
ZeroFive Web Design
dave@zerofive.co.uk
http://www.zerofive.co.uk

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html