[32571] in Perl-Users-Digest
Perl-Users Digest, Issue: 3840 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 18 09:09:19 2012
Date: Tue, 18 Dec 2012 06:09:05 -0800 (PST)
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, 18 Dec 2012 Volume: 11 Number: 3840
Today's topics:
Company web-site (all perl CGI) re-design, suggestions? <justin.1211@purestblue.com>
Re: Company web-site (all perl CGI) re-design, suggesti <cartercc@gmail.com>
form submission to two pages (Perl, CGI, JavaScript) <cartercc@gmail.com>
Re: form submission to two pages (Perl, CGI, JavaScript <glex_no-spam@qwest-spam-no.invalid>
Re: form submission to two pages (Perl, CGI, JavaScript <ben@morrow.me.uk>
Re: help - how to find what is the code for "+/-" symbo (Seymour J.)
Re: help - how to find what is the code for "+/-" symbo <rvtol+usenet@xs4all.nl>
Re: help - how to find what is the code for "+/-" symbo <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 17 Dec 2012 14:24:00 +0000
From: Justin C <justin.1211@purestblue.com>
Subject: Company web-site (all perl CGI) re-design, suggestions?
Message-Id: <0hm3q9-srb.ln1@zem.masonsmusic.co.uk>
The in-house web-site is about twenty pages. Most of
the pages are the front end to perl programs that
perform various tasks. The index page at the base URL
contains links to each of the other pages. The pages
each have their own directory, and are index.cgi so
that, from the top level, the link is self explanatory,
eg: http://inhouse/postage_calculator/.
Every time a new program is added (or a new static
page), a directory is created and a standard template
is copied to the directory. The template takes care of
layout, template items, linking style.css, and looks
for either body.txt or program.pl in the current
directory which then takes care of the pages purpose.
The site is getting complex, several modules have been
written to take care of common tasks (database look-ups
mainly). The more I look at the site the more I know
there must be a better way, it's time consuming to add
new modules to each of the existing templates, and
check that none have been missed, and that nothing gets
broken by the addition.
I'm sure I should do away with the 'site' concept, the
whole pages and directory tree structure, and have just
one program at the base URL, and that one program call
methods for whatever task is requested. I think I
should also implement a system by which the program
remembers data submitted between calls rather than
relying on hidden form fields, or a tmp file and
relying on the infrequency of use to prevent requests
clashing (user 2 getting the results of user 1's
query).
The current site uses the CGI module. I believe this is
no longer flavour of the month. It has served well
enough, but there has been some serious head-scratching
trying to bend it to fit some of my requirements, I
look forward to learning something new. I think I could
make CGI fit, and I am familiar with it, but if there's
a better way then that's what I'd rather be doing, as
much for learning something new as for doing this
'right'.
I welcome any suggestions, or pointers to
documentation, for where I might start or how I might
proceed.
I have considered CMS for this, but that doesn't seem
as appropriate for programs, which tend to hang around
for years, as it does for 'news' stories which tend to
update often. I'm very happy to be disuaded of this if
someone thinks I should be going with CMS.
Thank you for any comments, suggestions, pointers to
reading matter.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Mon, 17 Dec 2012 11:09:26 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Company web-site (all perl CGI) re-design, suggestions?
Message-Id: <344d89d2-178e-449a-b4e7-2d038fc07545@googlegroups.com>
On Monday, December 17, 2012 9:24:00 AM UTC-5, Justin C wrote:
Justin,
I've never down any real big sites, but I've done a bunch of smallish sites=
, some with as many as 50 pages, almost all of them (if not all of them) ar=
e interfaces to databases.
I use CGI and it's done every thing I've asked it to do. I have learned to =
do it the way i describe below mostly by trial and error, and by writing a =
lot of very bad code over the years. I am completely comfortable with this =
approach.
The only HTML page I write is the main entry page to the 'site.' All the ot=
her HTMl 'pages' are dynamically created from the query parameters passed i=
n by the user and the content in the database.
All of the HTML content, and graphical content, I keep in a database, and I=
write a console for the maintainers to maintain and update the content the=
mselves.
For example, suppose I have a table that looks like this:
create table HTML (
page text primary key,
content text );
The content might look like this in CSV:
"products/","Welcome to our products page."
"products/office/","Here are our office products."
"products/cleaning/","Here are our cleaning products."
"products/books/","Here are our books."
"staff/","Meet our staff."
"staff/sales/","Our friendly sales people."
"staff/techs/","Our competent technical people."
"staff/management/","Our superior management team."
You might get your navigation device by something like this:
select page from HTML;
and then parse the keys and create your various menu bars.
When your user clicks on a link, you generate a query like this:
select content from HTML where page =3D 'staff/sales/';
and then use your Perl script to spit out the HTML content to the web serve=
r.
Typically I would modularize the app, have a SQL module, an HTML module, an=
d maybe a couple of others. Mostly, the 'main' script is very simple and ju=
st calls functions.
Your script might look a little like this:
#! perl
use strict;
use warnings;
use CGI;
use SQL; # a custom module
use HTML; # a custom module
my $page =3D param(page');
# these functions will return a hash reference that contains the data
my $nav =3D SQL::get_nav($page);
my $content =3D SQL::get_content($page);
HTML::print_header($page);
HTML::print_nav($page);
HTML::print_content($page);
HTML::print_nav($page);
HTML::print_footer($page);
exit(0);
For an illustration of what this would look like, go to
http://mupd.org
Look at the URLs displayed in the address bar. There are no HTML pages beca=
use there's no HTML. Every page is dynamically created from the links click=
ed by the user.
This probably isn't the best way to do it, but it's cheap, fast, and takes =
the burden of maintaining the site off me. And yeah, I know the site isn't =
anything to write home about, but I don't hold myself out as a web design a=
rtist, just a database guy who writes front ends to databases.
CC.
> The site is getting complex, several modules have been
> written to take care of common tasks (database look-ups
> mainly). The more I look at the site the more I know
> there must be a better way, it's time consuming to add
> new modules to each of the existing templates, and
> check that none have been missed, and that nothing gets
> broken by the addition.
...
> I'm sure I should do away with the 'site' concept, the
> whole pages and directory tree structure, and have just
> one program at the base URL, and that one program call
> methods for whatever task is requested.
...
> The current site uses the CGI module. I believe this is
> no longer flavour of the month. It has served well
> enough, but there has been some serious head-scratching
> trying to bend it to fit some of my requirements, I
> look forward to learning something new.
------------------------------
Date: Mon, 17 Dec 2012 11:24:29 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: form submission to two pages (Perl, CGI, JavaScript)
Message-Id: <f0162e6d-b88d-4d06-bf79-56851634fe00@googlegroups.com>
I have a rather long list, perhaps named 'list_presidents' that allows user=
s to update single records. It might look like this, with the convention th=
at [[input text][submit N]] is an HTML form:
1 | George Washington | [[input text][submit 1]]
2 | John Adams | [[input text][submit 2]]
3 | Thomas Jefferson | [[input text][submit 3]]
4 | James Madison | [[input text][submit 4]]
The form field looks like this:
<form method=3D"post" action=3D"update_pres" name=3D"pres_N">
...
<input type=3D"submit" value=3D"Update President N" />
</form>
I would like to do one of three things but quite frankly don't know how. Th=
is post is the culmination of a fairly long time flailing around, and I'd l=
ike a little help --- even if it's confirmation that what I want is not pos=
sible (which I'm beginning to suspect is the case.)
1. When the user clicks on the submit button, leave the user on the same pa=
ge but execute a script in the background that updates the underlying datab=
ase.
2. When the user clicks on the submit button, leave the user on the same pa=
ge but open a new page that confirms that the database has been updated.
3. When the user clicks on the submit button, go to a new page that confirm=
s the update but then immediately returns to the prior page.
The problem is that the table has about 40,000 records, and there are about=
six filters, some of which have fifty or so options, and they all can be m=
ultiply selected. It was a lot faster and simpler when I had just a couple =
of thousand records and a couple of simple filters, but this has grown from=
a sweet innocent baby to a strapping adult man, and I need some help with =
it.
Thanks, CC.
------------------------------
Date: Mon, 17 Dec 2012 15:00:52 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: form submission to two pages (Perl, CGI, JavaScript)
Message-Id: <50cf8804$0$9081$815e3792@news.qwest.net>
On 12/17/12 13:24, ccc31807 wrote:
> I have a rather long list, perhaps named 'list_presidents' that allows users to update single records. It might look like this, with the convention that [[input text][submit N]] is an HTML form:
>
> 1 | George Washington | [[input text][submit 1]]
> 2 | John Adams | [[input text][submit 2]]
> 3 | Thomas Jefferson | [[input text][submit 3]]
> 4 | James Madison | [[input text][submit 4]]
>
> The form field looks like this:
> <form method="post" action="update_pres" name="pres_N">
> ...
> <input type="submit" value="Update President N" />
> </form>
>
> I would like to do one of three things but quite frankly don't know how. [...]>
None of these really has anything to do with Perl/server side...
> 1. When the user clicks on the submit button, leave the user on the same page but execute a script in the background that updates the underlying database.
>
> 2. When the user clicks on the submit button, leave the user on the same page but open a new page that confirms that the database has been updated.
>
> 3. When the user clicks on the submit button, go to a new page that confirms the update but then immediately returns to the prior page.
>
That last one and it would make for a poor user experience.
Read up on AJAX. A JavaScript framework, like JQuery, makes doing these
things much easier than writing it yourself. There are many JavaScript
libraries that you can choose from and they each simplify AJAX calls,
going through the DOM, validating forms, dynamically show/hide
elements, etc. Other popular libs: Ext JS, MooTools, Prototype,
GWT, YUI, etc....
See: http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks
------------------------------
Date: Mon, 17 Dec 2012 22:05:41 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: form submission to two pages (Perl, CGI, JavaScript)
Message-Id: <lih4q9-2sl.ln1@anubis.morrow.me.uk>
Quoth ccc31807 <cartercc@gmail.com>:
> I have a rather long list, perhaps named 'list_presidents' that allows
> users to update single records. It might look like this, with the
> convention that [[input text][submit N]] is an HTML form:
>
> 1 | George Washington | [[input text][submit 1]]
> 2 | John Adams | [[input text][submit 2]]
> 3 | Thomas Jefferson | [[input text][submit 3]]
> 4 | James Madison | [[input text][submit 4]]
>
> The form field looks like this:
> <form method="post" action="update_pres" name="pres_N">
> ...
> <input type="submit" value="Update President N" />
> </form>
>
> I would like to do one of three things but quite frankly don't know how.
> This post is the culmination of a fairly long time flailing around, and
> I'd like a little help --- even if it's confirmation that what I want is
> not possible (which I'm beginning to suspect is the case.)
>
> 1. When the user clicks on the submit button, leave the user on the same
> page but execute a script in the background that updates the underlying
> database.
This is straightforward. Just use the same logic as you would usually
use to keep the user on the same page, but before returning the response
fire off a background task to perform the update. Since you are using
CGI the most straightforward way to do this is to fork and perform the
update in the child.
> 2. When the user clicks on the submit button, leave the user on the same
> page but open a new page that confirms that the database has been
> updated.
This can only be done on the client side. The simplest way is to specify
target="_blank" on the <form> element. This will cause the whole form
submission to happen in a new window/tab, and the CGI can then return
whatever status information it likes.
> 3. When the user clicks on the submit button, go to a new page that
> confirms the update but then immediately returns to the prior page.
This, again, can only be done client-side, but this time the
modification is to the page returned from the CGI rather than the page
which invokes it. The simplest way is to use <meta refresh>, but that
will make a fresh request for the previous page rather than simply going
back to it (so, for instance, the page will be redisplayed at the top,
and any form entry the user has done will be lost). An alternative is to
arrange to call window.history.back() from a Javascript onload handler,
but doing this right requires a certain amount of care to ensure the
whole page has in fact loaded and been displayed to the user for a
reasonable amount of time before going back to the previous page.
As a general rule I hate sites which do this sort of thing. IMHO a
better option would be to provide a link on the page which either calls
window.history.back() or simply links to the previous page, which allows
the user to decide when they've finished reading the update page and
they want to return to the previous one.
An alternative I quite like is to display the status information inline,
close to the form the user has just operated, either using AJAX or by
redisplaying the whole page.
> The problem is that the table has about 40,000 records, and there are
> about six filters, some of which have fifty or so options, and they all
> can be multiply selected.
This is a completely different problem from the UI issue. You need a
real database: I would recommend Postgres.
Ben
------------------------------
Date: Sun, 16 Dec 2012 09:31:28 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: help - how to find what is the code for "+/-" symbol copied from Windows app
Message-Id: <50cddb40$19$fuzhry+tra$mr2ice@news.patriot.net>
In <slrnkcrcv6.htc.hjp-usenet2@hrunkner.hjp.at>, on 12/16/2012
at 12:43 PM, "Peter J. Holzer" <hjp-usenet2@hjp.at> said:
>At least an unintended charset conversion can be easily undone
>with iconv or similar tools
Not when there are no MIME headers. Absent charset, there's no way to
know what the non-ASCII code points are.
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
------------------------------
Date: Mon, 17 Dec 2012 22:52:02 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: help - how to find what is the code for "+/-" symbol copied from Windows app
Message-Id: <50cf9402$0$6880$e4fe514c@news2.news.xs4all.nl>
On 2012-12-15 13:34, Ben Morrow wrote:
> [recognizing ± with RE]
>
> use HTML::Entities "decode_entities";
> my $plusmn = decode_entities "±";
Realize that HTML::Entities is not in core.
And don't forget quotemeta:
perl -wle '
my $dot = "\x{2E}";
print "1:", "a" =~ /$dot/;
print "2:", "a" =~ /\x{2E}/;
'
1:1
2:
--
Ruud
------------------------------
Date: Mon, 17 Dec 2012 22:12:51 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: help - how to find what is the code for "+/-" symbol copied from Windows app
Message-Id: <30i4q9-2sl.ln1@anubis.morrow.me.uk>
Quoth "Dr.Ruud" <rvtol+usenet@xs4all.nl>:
> On 2012-12-15 13:34, Ben Morrow wrote:
>
> > [recognizing ± with RE]
> >
> > use HTML::Entities "decode_entities";
> > my $plusmn = decode_entities "±";
>
> Realize that HTML::Entities is not in core.
OK, use Pod::Escapes instead.
> And don't forget quotemeta:
>
> perl -wle '
> my $dot = "\x{2E}";
> print "1:", "a" =~ /$dot/;
> print "2:", "a" =~ /\x{2E}/;
> '
> 1:1
> 2:
I'm not sure what this is supposed to illustrate. Plus-minus is not
ASCII, so it can't be a regex metachar, so it doesn't matter whether you
quotemeta it or not.
Ben
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 3840
***************************************