Web Interface and index.pl separated?!?

N

Nikos

Inside my webpage index.pl i ahve the Perl code and the interface of the
page: Do you think that i must separate the page's interface in a file
by itself and then in another index.pl make calculations and stuff with it:

i have i as follows to generate graphics. here is a asmall part:

print start_form(-action=>"show.pl");
print table( {-border=>1, -width=>"60%", -align=>"center",
-style=>"border: ridge magenta; color: lime; font-family: Times;
font-size: 18", -background=>"../data/images/swirl.jpg"},
Tr( {-align=>'center'}, td( "Ðþò óå ëÝíå áäåëöÝ?" ),
td( textfield( 'onoma' ))),
Tr( {-align=>'center'}, td( "ÐïéÜ åßíáé ç ãíþìç óïõ ãéá ôçí åõ÷ïýëá
\"Êýñéå Éçóïý ×ñéóôÝ ÅëÝçóïí Ìå\"?"
), td( textarea( -name=>'sxolio', -rows=>5, -columns=>30 ))),
Tr( {-align=>'center'}, td( "ÌïéñÜóïõ ìáæß ìáò ìßá êáôÜ ôç ãíþìç óïõ
èáõìáóôÞ ðñïóùðéêÞ óïõ ðíåõìáôéêÞ
åìðåéñßá
áðü êÜðïéïí ãÝñïíôá ðñïò þöåëïò ôùí
õðïëïßðùí áäåëöþí (áí öõóéêÜ Ý÷åéò
:)" ), td( textarea( -name=>'symvan', -rows=>7, -columns=>30 ))),
Tr( {-align=>'center'}, td( "Ðïéü åßíáé ôï e-mail óïõ?" ),
td( textfield( 'email' ))),
Tr( {-align=>'center'}, td( submit( 'ÅìöÜíéóç üëùí ôùí áðüøåùí'
)), td( submit( 'ÁðïóôïëÞ' ))));
print end_form(), br(), br();

also inside index.pl a have javascript embedded in a here document.

Is this wrong approach?

For example how could i rewrite the above script?
The funny stuff is actually Greek! :)
 
T

Tad McClellan

Nikos said:
Inside my webpage index.pl


That is a mighty strange name for a webpage.

They usually have a .html or .htm filename extension...

i ahve the Perl code


You cannot put Perl code into a webpage.

(well you can, but it will not be executed, so what would be the point?)
 
A

axel

Nikos said:
Inside my webpage index.pl i ahve the Perl code and the interface of the
page: Do you think that i must separate the page's interface in a file
by itself and then in another index.pl make calculations and stuff with it:

It is probably easiest to work with the both in the same file.
i have i as follows to generate graphics. here is a asmall part:
print start_form(-action=>"show.pl");
print table( {-border=>1, -width=>"60%", -align=>"center",
-style=>"border: ridge magenta; color: lime; font-family: Times;
font-size: 18", -background=>"../data/images/swirl.jpg"},
Tr( {-align=>'center'}, td( "??? ?? ???? ???????" ),
td( textfield( 'onoma' ))),
Tr( {-align=>'center'}, td( "???? ????? ? ????? ??? ??? ??? ???????
\"????? ????? ?????? ??????? ??\"?"
), td( textarea( -name=>'sxolio', -rows=>5, -columns=>30 ))),
Tr( {-align=>'center'}, td( "???????? ???? ??? ??? ???? ?? ????? ???
???????? ????????? ??? ??????????
????????
??? ??????? ??????? ???? ?????? ???
????????? ??????? (?? ?????? ?????
:)" ), td( textarea( -name=>'symvan', -rows=>7, -columns=>30 ))),
Tr( {-align=>'center'}, td( "???? ????? ?? e-mail ????" ),
td( textfield( 'email' ))),
Tr( {-align=>'center'}, td( submit( '???????? ???? ??? ???????'
)), td( submit( '????????' ))));
print end_form(), br(), br();

also inside index.pl a have javascript embedded in a here document.

Is this wrong approach?

No... it is whatever you find most convenient.
For example how could i rewrite the above script?
The funny stuff is actually Greek! :)

One way would be to do the calculations required and then print all the
HTML with any results inserted as a 'here' document (or several to keep
the relevant calculations close to the output templates).

But then I have never really seen much point in adding an extra layer of
complexity by using functions in creating HTML.

Axel
 
L

Lord0

"Do you think that i must separate the page's interface in a file by itself
and then in another index.pl make calculations and stuff with it:"

It *IS* easier to put everything in one place but this can quickly become
unmaintainable for anything but the smallest project. Many "design patterns"
would suggest that you keep your presentation i.e. your webpage and your
business layer i.e. your calculations seperate. You may want to google for
"model view controller" for some more info on this.
 
A

A. Sinan Unur

Nikos said:
Inside my webpage index.pl i ahve the Perl code and the interface of
the page: Do you think that i must separate the page's interface in a
file by itself and then in another index.pl make calculations and
stuff with it:

The simplest templating solution that results in complete separation of
HTML, Javascript, CSS and what not is, IMHO, HTML::Template. You might
want to give it a shot.

Sinan
 
N

Nikos

Tad said:
That is a mighty strange name for a webpage.

They usually have a .html or .htm filename extension...
You cannot put Perl code into a webpage.

(well you can, but it will not be executed, so what would be the point?)

Itc a CGI script. My webpage is locates at http://www.nikolas.tk and the
index file is not a index.html but an index.pl

Problem is that i have both the web interface and the stuff iam doing
with it in asingle file(index.pl).

I just want to know if its better to separate Perl code and maybe design
the interface with Dreamweaver for example.

The question is if the the 2 things will be able to cooperate in somw way.
 
J

J. Gleixner

Nikos said:
I just want to know if its better to separate Perl code and maybe design
the interface with Dreamweaver for example.

The question is if the the 2 things will be able to cooperate in somw way.

For one page, it doesn't matter, do it however you'd like and move on.
For multiple pages, Web based applications, etc. then yes, separate your
HTML from your code, and separate your Javascript and CSS while you're
at it.

There are many perl based systems already developed. HTML::Template,
Template Toolkit, HTML::Mason, etc. There is a lot of documentation
along with many tutorials available.

However. Looking at your original example, it doesn't appear that you
have any need to do anything dynamic. If you don't need to change/add
anything on your page, like set variables/layout based on user input,
time of day, database query, etc. then don't make it a script/CGI, just
use HTML. Use whatever you want to design the HTML.
 
N

Nikos

J. Gleixner said:
However. Looking at your original example, it doesn't appear that you
have any need to do anything dynamic. If you don't need to change/add
anything on your page, like set variables/layout based on user input,
time of day, database query, etc. then don't make it a script/CGI, just
use HTML. Use whatever you want to design the HTML.

My webpage is dynamic, read time and makes mysql database query.
I use cgi.pm because i dont want to have p[ure html in my page.
But i think it might be better if i create the graphicss with
dreamweaver. but then would that graph.html work with with indx.pl?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top