[25752] in Perl-Users-Digest
Perl-Users Digest, Issue: 7992 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 19 14:10:27 2005
Date: Tue, 19 Apr 2005 11:10:19 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 19 Apr 2005 Volume: 10 Number: 7992
Today's topics:
Re: Perl + Dreamweaver? <hackeras@gmail.com>
Re: Perl + Dreamweaver? <nobody@dev.null>
Re: Perl + Dreamweaver? <noreply@gunnar.cc>
Re: Perl + Dreamweaver? <t.k.fuglerud@usit.uio.no>
Re: Perl + Dreamweaver? <hackeras@gmail.com>
Re: Perl + Dreamweaver? <flavell@ph.gla.ac.uk>
Re: Perl + Dreamweaver? <noreply@gunnar.cc>
Re: Perl + Dreamweaver? <noreply@gunnar.cc>
Re: Perl + Dreamweaver? <hackeras@gmail.com>
Re: Perl + Dreamweaver? <sbryce@scottbryce.com>
Re: Perl + Dreamweaver? <sbryce@scottbryce.com>
Re: Perl + Dreamweaver? <hackeras@gmail.com>
Re: Perl + Dreamweaver? <hackeras@gmail.com>
Re: Perl + Dreamweaver? <flavell@ph.gla.ac.uk>
Re: Perl + Dreamweaver? <mikeh@perusion.net>
Re: Perl + Dreamweaver? <hackeras@gmail.com>
Re: Perl + Dreamweaver? <sbryce@scottbryce.com>
Re: Perl + Dreamweaver? <sbryce@scottbryce.com>
Re: Perl + Dreamweaver? <hackeras@gmail.com>
Re: Perl + Dreamweaver? <pilkowsk@informatik.uni-marburg.de>
Re: Perl + Dreamweaver? <sbryce@scottbryce.com>
Re: Perl + Dreamweaver? <hackeras@gmail.com>
Re: Perl + Dreamweaver? <hackeras@gmail.com>
Re: Perl + Dreamweaver? <sbryce@scottbryce.com>
Re: Perl on Rails? sigzero@gmail.com
Q on BEGIN and INIT <jkrugman345@yahbitoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 19 Apr 2005 16:06:30 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d42vol$jrs$1@nic.grnet.gr>
Gunnar Hjalmarsson wrote:
[snip]
> I don't use Dreamweaver, but I suppose that you can use it to edit such
> a template to your liking.
Thank you but it is still complicated.
In your opinion whats the easiest way of creating a Perl CGI Webpage and
why?
Perl + cgi.pm ? (the way i have it now)
Perl + Dreamweaver ?
Perl + Style Sheets ?
Iam really trying to fugure out the easiet method for implementing this.
cgi.pm is ok but it needs a lot of width, height, border, size,
font-family and stuff if you ahve it in a a index.pl that messes the
whole page up.
------------------------------
Date: Tue, 19 Apr 2005 09:18:07 -0400
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Perl + Dreamweaver?
Message-Id: <oy79e.2684$lz1.140@lakeread01>
Nikos wrote:
> Lord0 wrote:
>
>> "its very dull writing stuff like this:"
>>
>> I know this doesn't really answer your question but have a look at
>> HTML::Template
>
> What i want to do is "Separation of HTML and code".
>
> I though that i can create my fancy hmtl page with dreamweaver and then
> somehow(dont know how) join my code and html so they work together) Is
> that possbile with dreamweaver? i must somehow create the html too...
>
> If you please give a simple example of how can i simple perl script work
> with html::template i would be grateful. I took a look at perldoc.com
> but i didnt understand it.
Is it really PHP you are looking for?
------------------------------
Date: Tue, 19 Apr 2005 15:18:14 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl + Dreamweaver?
Message-Id: <3ckf18F6no9jgU1@individual.net>
Nikos wrote:
> Gunnar Hjalmarsson wrote:
>
> [snip]
>
>> I don't use Dreamweaver, but I suppose that you can use it to edit
>> such a template to your liking.
>
> Thank you but it is still complicated.
In what way do you find that example complicated?
If you want to create web pages dynamically (which I suppose you do...),
you need to take the time to learn how to do it.
> In your opinion whats the easiest way of creating a Perl CGI Webpage and
> why?
>
> Perl + cgi.pm ? (the way i have it now)
I like the idea of separating code and HTML, so I prefer templates
before CGI.pm's HTML generating stuff. And IMHO it's easier than using
CGI.pm.
> Perl + Dreamweaver ?
Dreamweaver is just an HTML editor, isn't it?
> Perl + Style Sheets ?
What have style sheets to do with dynamic web content?? Or isn't that
what you want?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 19 Apr 2005 15:25:58 +0200
From: "Tor Fuglerud" <t.k.fuglerud@usit.uio.no>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d430td$nuo$1@readme.uio.no>
"Nikos" <hackeras@gmail.com> wrote in message
news:d42vol$jrs$1@nic.grnet.gr...
<snip>
> Iam really trying to fugure out the easiet method for implementing this.
> cgi.pm is ok but it needs a lot of width, height, border, size,
> font-family and stuff if you ahve it in a a index.pl that messes the whole
> page up.
Try to put as much layout as posible in a stylesheet, that way you don't
have to give formating detail in the script.
(not much to do with perl but that's what I always do when using CGI.pm)
--
Tor Fuglerud
------------------------------
Date: Tue, 19 Apr 2005 16:32:25 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d43198$ld1$1@nic.grnet.gr>
Gunnar Hjalmarsson wrote:
> Nikos wrote:
> In what way do you find that example complicated?
The way you are passing/replacing the values from the perl file to the
variables in html page.
I didn't understnad it.
>> Perl + Dreamweaver ?
>
>
> Dreamweaver is just an HTML editor, isn't it?
Well yes, but you can create hmtl web pages very fast with it and
without messing with the <tags>
>> Perl + Style Sheets ?
>
> What have style sheets to do with dynamic web content?? Or isn't that
> what you want?
Yes dynamic contents is what i want.
------------------------------
Date: Tue, 19 Apr 2005 14:43:34 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Perl + Dreamweaver?
Message-Id: <Pine.LNX.4.62.0504191441250.21492@ppepc56.ph.gla.ac.uk>
On Tue, 19 Apr 2005, Gunnar Hjalmarsson wrote:
> Dreamweaver is just an HTML editor, isn't it?
My colleague who uses it seems to produce great gobs of CSS and
Javascript, so "no", it's not "just" an HTML editor.
> What have style sheets to do with dynamic web content??
Of course, "dynamic" web content can mean at least three different
contradictory things. Well, at least four... Nobody expects...
------------------------------
Date: Tue, 19 Apr 2005 15:48:51 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl + Dreamweaver?
Message-Id: <3ckgqpF6oin73U1@individual.net>
Nikos wrote:
> Gunnar Hjalmarsson wrote:
>> In what way do you find that example complicated?
>
> The way you are passing/replacing the values from the perl file to the
> variables in html page.
> I didn't understnad it.
I used Perl's s/// operator. If you use HTML::Template instead, you
don't need to bother about regular expressions and such.
Modified mytemplate.html:
<html><head><title><TMPL_VAR NAME=HEADER></title></head>
<body><h1><TMPL_VAR NAME=HEADER></h1>
<p>This is a <TMPL_VAR NAME=VAR1> for illustrating the
principles with a <TMPL_VAR NAME=VAR2>.</p>
</body></html>
Modified script:
#!/usr/bin/perl -T
use strict;
use warnings;
use HTML::Template;
use CGI;
my $q = CGI->new;
my $tmpl = HTML::Template->new(filename => 'mytemplate.html');
my %tmplvar = (
HEADER => 'My Template',
VAR1 => 'template',
VAR2 => 'templating system',
);
for my $var (keys %tmplvar) {
$tmpl->param( $var => $tmplvar{$var} );
}
print $q->header, $tmpl->output;
__END__
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 19 Apr 2005 15:57:16 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl + Dreamweaver?
Message-Id: <3ckhajF6omn3oU1@individual.net>
Alan J. Flavell wrote:
> On Tue, 19 Apr 2005, Gunnar Hjalmarsson wrote:
>> Dreamweaver is just an HTML editor, isn't it?
>
> My colleague who uses it seems to produce great gobs of CSS and
> Javascript, so "no", it's not "just" an HTML editor.
s/just/mostly/
>> What have style sheets to do with dynamic web content??
>
> Of course, "dynamic" web content can mean at least three different
> contradictory things. Well, at least four... Nobody expects...
Well, as I know you understood, I had difficulties to understand how
style sheets could be an alternative to using templates or CGI.pm. Maybe
I could have expressed myself more clearly. :)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 19 Apr 2005 17:05:51 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d4337v$n4m$1@nic.grnet.gr>
Alan J. Flavell wrote:
> On Tue, 19 Apr 2005, Gunnar Hjalmarsson wrote:
>
>
>>Dreamweaver is just an HTML editor, isn't it?
>
>
> My colleague who uses it seems to produce great gobs of CSS and
> Javascript, so "no", it's not "just" an HTML editor.
How does he passes values to the pages he produces with Dreamweaver?
By using Dreamweaver?
------------------------------
Date: Tue, 19 Apr 2005 08:34:11 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <0eednet0csF_i_jfRVn-jw@comcast.com>
Nikos wrote:
> In your opinion whats the easiest way of creating a Perl CGI Webpage
> and why?
>
> Perl + cgi.pm ? (the way i have it now)
> Perl + Dreamweaver ?
> Perl + Style Sheets ?
CGI.pm, DreamWeaver and CSS do three very different things. Use the ones
that do the job you want to do. You will probably wind up using all
three for different aspects of this task.
> I am really trying to fugure out the easiet method for implementing
> this.
You have already been pointed to HTML::Template. That is probably the
easiest tool you will find to separate HTML from your Perl script. There
are other templating tools that will also work.
If there is something specific about HTML::Template that you don't
understand, please ask a specific question that will help clear up your
confusion.
------------------------------
Date: Tue, 19 Apr 2005 08:42:23 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <2cednQsFEqtQhfjfRVn-3g@comcast.com>
Nikos wrote:
> How does he passes values to the pages he produces with Dreamweaver?
> By using Dreamweaver?
It is beginning to look like you don't really understand the process
well enough to understand how to use the tools available.
Come up with a short, simple example to try out. If you can't get it to
work, post what you tried, and we can help. Gunnar gave you a good
example to start with.
All you are doing now is telling us that you don't understand. We know
that, but it doesn't help us help you.
------------------------------
Date: Tue, 19 Apr 2005 17:51:08 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d435st$q5u$1@nic.grnet.gr>
Scott Bryce wrote:
> Nikos wrote:
>
>> In your opinion whats the easiest way of creating a Perl CGI Webpage
>> and why?
>>
>> Perl + cgi.pm ? (the way i have it now)
>
> > Perl + Dreamweaver ?
> > Perl + Style Sheets ?
>
> CGI.pm, DreamWeaver and CSS do three very different things. Use the ones
> that do the job you want to do. You will probably wind up using all
> three for different aspects of this task.
One is enouph thank you! :-)
>> I am really trying to fugure out the easiet method for implementing
>> this.
>
>
> You have already been pointed to HTML::Template. That is probably the
> easiest tool you will find to separate HTML from your Perl script. There
> are other templating tools that will also work.
>
> If there is something specific about HTML::Template that you don't
> understand, please ask a specific question that will help clear up your
> confusion.
Can you please give the simplest example on html::template?
------------------------------
Date: Tue, 19 Apr 2005 17:53:58 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d43626$q5u$2@nic.grnet.gr>
Scott Bryce wrote:
> Nikos wrote:
>
>> How does he passes values to the pages he produces with Dreamweaver?
>> By using Dreamweaver?
>
>
> It is beginning to look like you don't really understand the process
> well enough to understand how to use the tools available.
>
> Come up with a short, simple example to try out. If you can't get it to
> work, post what you tried, and we can help. Gunnar gave you a good
> example to start with.
>
> All you are doing now is telling us that you don't understand. We know
> that, but it doesn't help us help you.
Yes that is correct, i will try make somethign on my own to simplify
Gunnars example to something very easy and if i cant get it to work i
will post it here. Iam on to that now.
You are right. I must try that to see what *exactly* is what i dont
understand.
------------------------------
Date: Tue, 19 Apr 2005 16:06:36 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Perl + Dreamweaver?
Message-Id: <Pine.LNX.4.62.0504191606000.25937@ppepc56.ph.gla.ac.uk>
On Tue, 19 Apr 2005, Gunnar Hjalmarsson wrote:
> > My colleague who uses it seems to produce great gobs of CSS and
> > Javascript, so "no", it's not "just" an HTML editor.
>
> s/just/mostly/
OK, pax...
> Well, as I know you understood, I had difficulties to understand how
> style sheets could be an alternative to using templates or CGI.pm.
Sure, no offence to your main point, I was just heckling on a
side-issue that you'd raised.
all the best
------------------------------
Date: Tue, 19 Apr 2005 15:21:28 -0000
From: Mike Heins <mikeh@perusion.net>
Subject: Re: Perl + Dreamweaver?
Message-Id: <slrnd6a8fn.b3e.mikeh@bill.heins.net>
On 2005-04-19, Nikos <hackeras@gmail.com> wrote:
> Scott Bryce wrote:
>> Nikos wrote:
>>
>>> How does he passes values to the pages he produces with Dreamweaver?
>>> By using Dreamweaver?
>>
>>
>> It is beginning to look like you don't really understand the process
>> well enough to understand how to use the tools available.
>>
>> Come up with a short, simple example to try out. If you can't get it to
>> work, post what you tried, and we can help. Gunnar gave you a good
>> example to start with.
>>
>> All you are doing now is telling us that you don't understand. We know
>> that, but it doesn't help us help you.
>
> Yes that is correct, i will try make somethign on my own to simplify
> Gunnars example to something very easy and if i cant get it to work i
> will post it here. Iam on to that now.
>
> You are right. I must try that to see what *exactly* is what i dont
> understand.
The classic templating problems are:
1) How do you allow inline code without having the editor
kill your code syntax?
Some editors have a <notouch> CODE </notouch> setup
of some kind and you can instruct them not to relocate
comments. I don't know if Dreamweaver is one of these.
When I looked at this years ago, I found that most editors
would kill your code in some fashion or another -- moving
comments around, not allowing comments between table
elements, etc.
2) How do you specify URLs so that you can make them dynamic?
Almost all code is going to require rewriting URLs in some
fashion if you are going to remain relatively portable.
3) How do you use a common image library without having
to carry all images around with you or specify absolute
paths? A lot of the "components" you get with editors
screw this up by using JavaScript to load image -- almost
always without giving you control of the paths involved.
4) How do you dynamically specify page components and
get them inserted in the right place?
ASP has done a pretty good job of this, and I presume a lot of editors
support it. The big problem with ASP is that of all of the inline
templating styles, that you have to do something early in order
to get it inline in the proper place.
The best solution I have found is to do a complete templating
with two-pass processing. I use Interchange, and you can specify
a base template:
<html>
<head>
{{CSS}}
{{HEAD}}
</head>
<body>
<table>
<tr>
<td style="vertical-align: top; width: 20%">
{{LEFT}}
</td>
<td style="vertical-align: top; width: 60%; padding: 5px">
{{TOP}}
{{:DEFAULT}}
{{BOTTOM}}
</td>
<td style="vertical-align: top; width: 20%">
{{RIGHT}}
</td>
</table>
{{COPYRIGHT}}
</body>
</html>
Then you do code which fills those areas, and do a template substitution.
There can be a fair amount of string copying going on, which doesn't make
for the best performance, but for most applications it seems to work well.
XSLT is another thing to look at for a two-pass system -- obviously you
produce XML and then relocate it to a template.
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
Be patient. God isn't finished with me yet. -- unknown
------------------------------
Date: Tue, 19 Apr 2005 18:28:27 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d4382r$s69$1@nic.grnet.gr>
> If there is something specific about HTML::Template that you don't
> understand, please ask a specific question that will help clear up your
> confusion.
Here it is:
=================================
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
$number = int(rand(10)) + 1;
$name = "Nikos";
$day = "Tuesday";
open(FH, "<test.html") or die $!;
print $number, $name, $day;
==================================
<html>
<head>
<title>Today is $day!</title>
</head>
<body>
<h1>Hello $name, how are are you today?</h1>
<p>This is a random number generator: $number</p>
</body>
</html>
===================================
By making this simple script myself i have understanded that i dont know
how to pass the values from test.pl to test.html so that in runtime of
etst.html $number, $day and $name be replaced with a random number,
"tuesday" and "Nikos". In other words i dont know how to merge those 2
scripts.
Instead of that as i have it now i am just getting an output to the
console when i run perl test.pl.
------------------------------
Date: Tue, 19 Apr 2005 09:35:14 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <6uqdnfOrBNWtuPjfRVn-iQ@comcast.com>
Nikos wrote:
>> CGI.pm, DreamWeaver and CSS do three very different things. Use the ones
>> that do the job you want to do. You will probably wind up using all
>> three for different aspects of this task.
>
>
> One is enouph thank you! :-)
No. They are three different tools that do three different things. You
will use all three. Just like a carpenter uses a saw to cut wood, a
hammer to pound nails, and a tape measure to take measurments. You
cannot create dynamic web pages with JUST CSS or JUST CGI.pm or JUST an
HTML editor any more than a carpenter can build a house with JUST a hammer.
> Can you please give the simplest example on html::template?
Gunnar already did. Or you can start with the example in the docs.
http://search.cpan.org/~samtregar/HTML-Template-2.7/Template.pm
------------------------------
Date: Tue, 19 Apr 2005 09:51:20 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <oKednUThy8BqtfjfRVn-tA@comcast.com>
Nikos wrote:
> Here it is:
<code snipped>
And here it is using HTML::Template. Note that this simply sends output
to the console. I will leave it to you to build this into a CGI application.
Though this example does not make use of CGI.pm, I left the use
statements in, assuming that you will expand this into a script that
makes use of CGI.pm.
FWIW, All I did was start with your code, and copy the relevant changes
directly from the docs, with appropriate tweaks.
---------
#!/usr/bin/perl
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use HTML::Template;
my $number = int(rand(10)) + 1;
my $name = "Nikos";
my $day = "Tuesday";
my $template = HTML::Template->new(filename => 'test.tmpl');
$template->param(NUMBER => $number);
$template->param(NAME => $name);
$template->param(DAY => $day);
# Appropriate headers go here
print $template->output;
----------
<html>
<head>
<title>Today is <TMPL_VAR NAME=DAY>!</title>
</head>
<body>
<h1>Hello <TMPL_VAR NAME=NAME>, how are are you today?</h1>
<p>This is a random number generator: <TMPL_VAR NAME=NUMBER></p>
</body>
</html>
-----------
------------------------------
Date: Tue, 19 Apr 2005 19:15:26 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d43aqu$1qd$1@nic.grnet.gr>
Scott Bryce wrote:
> <code snipped>
Thnk you very much Scott but unfortunately somethings still look strange
to me. :-(
Iam still confused but thanks for trying to help me. Maybe i should give
up the HTML::Template stuff and return back to cgi.pm or learn css or
maybe just give up on web page design once for all.
------------------------------
Date: Tue, 19 Apr 2005 18:31:09 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Perl + Dreamweaver?
Message-Id: <3ckq1kF6o4juiU1@individual.net>
* Nikos schrieb:
> Scott Bryce wrote:
>> Nikos wrote:
>>
>>> In your opinion whats the easiest way of creating a Perl CGI Webpage
>>> and why?
>>>
>>> Perl + cgi.pm ? (the way i have it now)
>>> Perl + Dreamweaver ?
>>> Perl + Style Sheets ?
>>
>> CGI.pm, DreamWeaver and CSS do three very different things. Use the ones
>> that do the job you want to do. You will probably wind up using all
>> three for different aspects of this task.
>
> One is enouph thank you! :-)
Please read carefully. They do *different* things, really. "Perl and
CGI.pm" is generating the output when someone requested your webpage via
browser. "Dreamweaver" could be used to generate HTML pages, but has
nothing to do with Perl (and I don't think, they could interact at all).
"Stylesheets" are used to separate layout and content inside a webpage.
Now, it's your part to choose what you want. After reading this thread
it seems like:
* use Dreamweaver to generate templates
* use Perl and HTML::Template to fill the templates with content
>
> Can you please give the simplest example on html::template?
Gunnar has given a simple example on HTML::Template. Nevertheless I can
give you a rewrite of it, just to see how it works -- perhaps this gives
you the point you don't understand yet. Assume this in mytemplate.html:
<html>
<head>
<title><tmpl_var name=header></title>
</head>
<body>
<h1><tmpl_var name=header></h1>
<p>
This is a <tmpl_var name=var1> for illustrating the
principles with a <tmpl_var name=var2>.
</p>
</body>
</html>
This is an example of template that HTML::Template needs to work. The
tags named <tmpl_var> are the variables which will be filled in by a
Perl sript later. It's your job to generate such templates, either by
type them by hand or by using Dreamweaver, you mentioned above. But this
newsgroup is not the right place to ask, how (or if?) Dreamweaver could
be used for this. However, after you have such an template, you can fill
it by using Perl.
#!/usr/bin/perl
use strict;
use warnings;
# You need CGI.pm, eg. to generate a valid header, perhaps you're
# doing some other stuff with it, like parsing parameters.
use CGI;
use CGI::Carp qw( fatalsToBrowser );
# You need HTML/Template.pm to process your template.
use HTML::Template;
# Declare the vars you want to put into your template, this could
# be easily done with a hash. In general, you get your values by
# calculating something, connecting to a database etc.
my %tmplvar = (
HEADER => 'My Template',
VAR1 => 'template',
VAR2 => 'templating system'
);
# Now, all needed vars are saved in the hash. It's time to read in
# the template file.
my $tmpl = HTML::Template->new( filename => 'mytemplate.html' );
# Fill in the template with your values, here we do this in one step
# by passing the whole hash to param(). Gunnar has shown how to set
# each var separately.
$tmpl->param( %tmplvar );
# The vars are determined, the template is filled with them -- let's
# write it out. First the header (as usual, you know?), followed by
# the template's output.
print CGI::header(), $tmpl->output;
__END__
If you ignore all my comments, it's not really a long perl script, isn't
it? But that's really all, you have to do (I know, I wrote it already):
* generating the template and
* fill in the template
Dreamweaver could help you to generate the templates (perhaps), and Perl
does help you to fill them with your content. The Perl modules »CGI« and
»HTML::Template« are just helping you with that. Sure, you could reject
this help and stick your own with an regex (Gunnar has done this in his
first code snippet), but I don't recommend that.
Last but not least, your templates could contains style sheets (CSS).
That's the usual way to reduce formatting directives in HTML (doesn't
matter if it is an template or not).
Hope this helps.
regards,
fabian
------------------------------
Date: Tue, 19 Apr 2005 10:30:49 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <t7SdnbH4tseqr_jfRVn-jg@comcast.com>
Nikos wrote:
> Thnk you very much Scott but unfortunately somethings still look strange
> to me. :-(
>
> Iam still confused but thanks for trying to help me. Maybe i should give
> up the HTML::Template stuff
Take this example, and read the docs. Try making tweaks to the example
and see what happens.
> and return back to cgi.pm
Which serves a different purpose.
> or learn css or
Which also serves a different purpose.
> maybe just give up on web page design once for all.
Or find someone locally who can help until you understand it better?
------------------------------
Date: Tue, 19 Apr 2005 20:38:39 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d43fmv$6e6$1@nic.grnet.gr>
Fabian Pilkowski wrote:
[snip explained code]
Thanks a lot Fabian now its more clear to me but i still cant convert
this index.pl script i made with the use of cgi.pm to the HTML::Template
way. Here is is btw:
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI::Cookie;
use CGI qw(:standard);
use DBI;
use DBD::mysql;
@months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec');
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
$xronos = "$mday $months[$mon], $hour:$min";
$ip = $ENV{'REMOTE_ADDR'};
@numbers = split (/\./,$ip);
$address = pack ("C4", @numbers);
$host = gethostbyaddr ($address, 2) || $ip;
$host = "ΑΦΕΝΤΙΚΟ" if ( ($host eq "localhost") or ($host eq
"dslcustomer-221-228.vivodi.gr" or $host eq "dell") );
print header( -charset=>'iso-8859-7' );
print start_html( -style=>'../style.css', -title=>'Ψυχωφελή Πνευματικά
Κείμενα!' );
$db = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
? DBI->connect('DBI:mysql:nikos_db', 'root', '')
: DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', 'tiabhp2r')
or print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0;
#*******************************************************************************
@files = <../data/text/*.txt>;
@display_files = map( /([^\/]+)\.txt/, @files );
print start_form(-action=>'index.pl');
print p( {-align=>'center'}, font( {-size=>5, -color=>'Lime'},
'Λόγος Ψυχωφελής και Θαυμάσιος => ' ),
popup_menu( -name=>'select',
-values=>\@display_files ),
submit('ok'));
print end_form(), br();
$keimeno = param('select') or "Αρχική Σελίδα";
$st = $db->prepare( "SELECT host FROM logs" );
$st->execute();
while( $row = $st->fetchrow_hashref ) {
if( $host eq $row->{host} ) {
$hostmatch = 1;
}
}
if( param('select') and param('select') !~ /\.\./ )
{
open(FH, "<../data/text/$keimeno.txt") or die $!;
@data = <FH>;
close(FH);
$data = join('', @data);
$db->do( "UPDATE logs SET keimeno='$keimeno' WHERE host='$host'" )
or die $db->errstr;
}
elsif( $hostmatch == 1 )
{
$db->do( "UPDATE logs SET visits = visits + 1 WHERE host='$host'" )
or die $db->errstr;
$st = $db->prepare( "SELECT * FROM logs WHERE host='$host'" );
$st->execute();
$row = $st->fetchrow_hashref;
$data = "Καλώς ήρθες " .$host. "! Χαίρομαι πολύ που σε ξαναβλέπω!\n" .
"Τελευταία φορα ήρθες εδώ ως " .$row->{host}. " στις "
.$row->{xronos}. " !!\n" .
"Αυτή είναι η " .$row->{visits}. " φορά που επισκέφτεσαι την
σελίδα μου και χαίρομαι πολύ που την βρίσκεις ενδιαφέρουσα !!!\n" .
"Την τελευταία φορά διάβασες το κείμενο [ "
.$row->{keimeno}. " ]\n" .
"Ποιo λόγο θα ήθελες να μελετήσεις αυτήν τη φορά ?!?";
}
elsif( $hostmatch != 1 )
{
if ( $host ne "ΑΦΕΝΤΙΚΟ" )
{
$data = "Καλώς όρισες " .$host. "!\n" .
"Αυτή ειναι η 1η σου επίσκεψη εδώ πέρα! Ελπίζω να σου
αρέσει!\n" .
"Ανοίγοντας το παραπάνω drop-down menu επέλεξε το κείμενο
που θα ήθελες να διαβάσεις...";
$db->do( "INSERT INTO logs VALUES (null, '$host', '$xronos',
'$text', 1)" ) or die $db->errstr;
}
else
{
$data = "Τι χαμπάρια $host :-) Θυμήθηκες να με περιποιηθείς και
εμένα λιγάκι !?!";
}
}
$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;
#*******************************************************************************
print <<ENDOFHTML;
<html><head><title></title>
<script type='text/javascript'>
var textToShow = "$data";
var tm;
var pos = 0;
var counter = 0;
function init()
{ tm = setInterval("type()", 45) }
function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("DivText");
c = textToShow.charAt(pos++);
if (c.charCodeAt(0) != 10)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));
counter++;
if (counter >= 1800 && (c.charCodeAt(0) == 10 || c == "."))
{
d.appendChild(document.createElement("br"));
d.appendChild(document.createTextNode("Press any key..."));
counter = 0;
clearInterval(tm);
document.body.onkeypress = function () {
document.getElementById("DivText").innerHTML = '';
tm =
setInterval("type()", 50);
document.body.onkeypress = null; };
}
}
else
clearInterval(tm);
}
</script>
<body onload=init()>
<center>
<div id="DivText" align="Left" style="
background-image: url(../data/images/kenzo.jpg);
border: Ridge Orange 5px;
width: 850px;
height: 500px;
color: LightSkyBlue;
font-family: Times;
font-size: 18px;">
</div
ENDOFHTML
#*******************************************************************************
print br(), br(), br();
print start_form(-action=>'show.pl');
print table(
Tr( {-align=>'center'}, td( "Πώς σε λένε αδελφέ?" ),
td( textfield( 'onoma' ))),
Tr( {-align=>'center'}, td( "Ποιά είναι η γνώμη σου για την ευχούλα
\"Κύριε Ιησού Χριστέ Ελέησον Με\"?"
), td( textarea( -name=>'euxoula', -rows=>4, -columns=>25 ))),
Tr( {-align=>'center'}, td( "Μοιράσου μαζί μας μία κατά τη γνώμη σου
θαυμαστή προσωπική πνευματική εμπειρία
από κάποιον γέροντα προς ώφελος των
υπολοίπων αδελφών (αν φυσικά έχεις
:-)" ), td( textarea( -name=>'sxolio', -rows=>6, -columns=>25 ))),
Tr( {-align=>'center'}, td( "Ποιό είναι το e-mail σου?" ),
td( textfield( 'email' ))),
Tr( {-align=>'center'}, td( submit( 'Εμφάνιση όλων των απόψεων'
)), td( submit( 'Αποστολή' ))),
);
print end_form(), br(), br();
open(FH, "<../data/text/tips") or die $!;
@tips = <FH>;
close(FH);
@tips = grep { !/^\s*\z/s } @tips;
$tip = $tips[int(rand(@tips))];
print table(
Tr( td( {class=>'tip'}, $tip ))
);
$db->do( "UPDATE counter SET counter = counter + 1" ) if ($host ne
"ΑΦΕΝΤΙΚΟ");
$st = $db->prepare( "SELECT counter FROM counter" );
$st->execute();
$row = $st->fetchrow_hashref;
print br();
print table(
Tr( td( {class=>'host'}, $host )),
Tr( td( {class=>'xronos'}, $xronos )),
Tr( td( {class=>'counter'}, $row->{counter} ))
);
print a( {href=>'games.pl'},
img{src=>'../data/images/games.gif'} );
print p( {-align=>'right'}, a( {href=>'show.pl?onoma=showlog'}, font(
{-size=>2, -color=>'Lime'}, b( 'Last Update: 18/4/2005' ))));
What i am trying to figure out is if the above script would be more
straightforward with the use of HTML::Template.
I tried to do ti but i didnt managed it....as expected.
The idea is to Separate the html from the pure perl code(here we dont
have html really since i use cgi.pm) but by trying that i *must* write
from scratch the pure html code(which i am trying to avoid) of the
script and the pure perl code which of course this time would be much
smaller. But i also have Javascript inserted here....
Do you really think that the above script can be rewritten in a more
straightforward way considering the use of the methods we discussed?
If yes, can you guys help me convert it so to see if it fits me better...
I tried a little according to the directives you provided, but because i
made a lot of errors i stopped before i hit the keyboard and screen.
------------------------------
Date: Tue, 19 Apr 2005 20:41:25 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <d43fs5$6e6$2@nic.grnet.gr>
Scott Bryce wrote:
>> and return back to cgi.pm
>
> Which serves a different purpose.
But with cgi.pm i can print all the variables i want, its just that perl
code and html(cgi.pm's functions) is in the same file.
> Or find someone locally who can help until you understand it better?
Nobody i know, knows Perl :>
------------------------------
Date: Tue, 19 Apr 2005 11:55:51 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Perl + Dreamweaver?
Message-Id: <T5ednaKtf7m72_jfRVn-jQ@comcast.com>
Nikos wrote:
> What i am trying to figure out is if the above script would be more
> straightforward with the use of HTML::Template.
Probably, but I doubt anyone is going to go through all of that code to
show you how.
> The idea is to Separate the html from the pure perl code(here we dont
> have html really since i use cgi.pm)
The end result is still HTML.
> but by trying that i *must* write
> from scratch the pure html code(which i am trying to avoid)
In order to use ANY templating system, you will have to have an HTML
file in which to drop the desired values. There is no way around that.
You keep mentioning DreamWeaver. You could write the HTML in
Dreamweaver, then tweak the HTML to make a template from it.
> Do you really think that the above script can be rewritten in a more
> straightforward way considering the use of the methods we discussed?
You will have to decide whether you want to use CGI.pm to do HTML
output, or use a templating system.
------------------------------
Date: 19 Apr 2005 09:58:21 -0700
From: sigzero@gmail.com
Subject: Re: Perl on Rails?
Message-Id: <1113929901.308721.97220@f14g2000cwb.googlegroups.com>
Catalyst was designed with some insight from RoR.
http://search.cpan.org/dist/Catalyst/
Robert
------------------------------
Date: Tue, 19 Apr 2005 14:05:22 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Q on BEGIN and INIT
Message-Id: <d43372$frm$1@reader1.panix.com>
In Programming Perl, Third Edition, page 484, it says:
INIT blocks are really just like BEGIN blocks, except they let
the programmer distinguish construction that must happen at
compile phase from construction that must happen at run phase.
When you're running a script directly, that's not terribly
important because the compiler gets invoked every time anyway;
but when compilation is separate from execution, the distinction
can be crucial. The compiler may only be invoked once, and the
resulting executable may be invoked many times.
The last sentence suggests that if initialization code is stuck in
a BEGIN block for a program that is compiled once but run many
times, then the initialization will not be properly done except
for the very first execution. The only common scenario I could
think of where this separation of compilation and execution would
happen is something like mod_perl, but then I found this in Practical
mod_perl by Bekman and Cholet:
Perl calls [INIT and CHECK] blocks only during perl_parse( ),
which mod_perl calls once at startup time. Therefore, ...INIT
blocks don't work in mod_perl, for the same reason [this doesn't]:
panic% perl -e 'eval qq(INIT { print "ok\n" })'
So now I'm even more confused. If Perl indeed calls INIT only
during perl_parse, then I don't see how the excerpt from PP can be
correct, since it seems farfetched that parsing of the program
could occur multiple times for a single compilation.
My two questions are: 1) notwithstanding the excerpt from PP, in
the case of a script intended to be run under mod_perl, would a
BEGIN block be the right way to take care of initialization code,
like this
{
my $private; BEGIN { $private = 1 } sub foo {
# use $private } }
? And 2) what's a reasonably common, realistic scenario in which
compilation would happen once, execution many times, and the
distinction between BEGIN and INIT was meaningful in the sense
described by the PP excerpt above?
TIA!
jill
P.S. Is this the right forum for this question?
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7992
***************************************