Perl snippet question:
---------------------------------------------
#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';
my $new_page = new CGI("");
sub HTMLendFORM ($) {
my $new_page = $_[0];
print $new_page->end_form;
}
HTMLendFORM ($new_page);
print "\n\n";
---------------------------------------------
This above code produces "<div></div></form>". This ti me is odd, since
i only really want </form>. Does anyone have an explanation or another
way to use the CGI.pm library and produce only </form>. Yes I could just
use a print statement. But I am kind of curious to why?

Signature
------------------------------------------------------------------------
*Michael Barto*
Software Architect
LogiQwest Circle
LogiQwest Inc.
16458 Bolsa Chica Street, # 15
Huntington Beach, CA 92649
http://www.logiqwest.com/
mbarto@logiqwest.com <mailto:mbarto@logiqwest.com>
Tel: 714 377 3705
Fax: 714 840 3937
Cell: 714 883 1949
*'tis a gift to be simple*
------------------------------------------------------------------------
This e-mail may contain LogiQwest proprietary information and should be
treated as confidential.
Jeremiah Foster - 27 Sep 2007 22:02 GMT
> Perl snippet question:
>
[quoted text clipped - 21 lines]
> Yes I could just use a print statement. But I am kind of curious to
> why?
Why are you doing it this way? You do not need a sub and it is best
to use $q (or the functional interface) since if anyone has to read
your code they will recognize $q immediately but wonder what
$new_page is for. And why are you printing two new lines? New lines
do not show up in HTML.
Try this:
print $q->end_form();
That usually produces </form>
Michael Barto - 28 Sep 2007 07:17 GMT
This seems like a flame, but I will try and answer your question. The
reason why we are doing the HTML subroutines and so many others with key
at the start (e.g. JSCript, DB, make, get). is mostly to support long
term maintenance and parse out pieces of the code for a very large
project (divide and conquer). The modules libraries are maintained in a
consistent manner. The variables $new_page and $from_page also are
significant in this large code. It just helps the many people that have
to touch this code have an easier path getting though any maintenance.
The main program is nothing more than large set subroutine calls broken
down in sections. The subroutine calls are shared by many modules of
the large project.
Also, I really appreciate "jszinger@gmail.com" response as it did
clarify the issue and was very helpful.
>> Perl snippet question:
>>
[quoted text clipped - 32 lines]
>
> That usually produces </form>

Signature
------------------------------------------------------------------------
*Michael Barto*
Software Architect
LogiQwest Circle
LogiQwest Inc.
16458 Bolsa Chica Street, # 15
Huntington Beach, CA 92649
http://www.logiqwest.com/
mbarto@logiqwest.com <mailto:mbarto@logiqwest.com>
Tel: 714 377 3705
Fax: 714 840 3937
Cell: 714 883 1949
*'tis a gift to be simple*
------------------------------------------------------------------------
This e-mail may contain LogiQwest proprietary information and should be
treated as confidential.
Jeremiah Foster - 28 Sep 2007 12:54 GMT
> This seems like a flame, but I will try and answer your question.
> The reason why we are doing the HTML subroutines and so many others
[quoted text clipped - 8 lines]
> in sections. The subroutine calls are shared by many modules of
> the large project.
The "best practices" procedure is to use MVC. (Model, View, Control)
- this provides separation of logic and presentation and
significantly aids in the long term maintenance of your code. Look at
Damian Conway's book; Perl Best Practices.
By not following best practices you run the risk of making your code
write only. An experienced perl programmer would have a hard time
reading it and re-factor it according to best practices.
Following best practices will significantly increase readability,
maintenance, and quality of your code.
Jeremiah
Jeremiah Foster - 27 Sep 2007 22:13 GMT
From perldoc CGI:
A Lurking Trap! Some of the form-element generating methods
return multiple tags. In a scalar context, the tags will be
concatenated together with spaces, or whatever is the current value
of the $" global. In a list context, the methods will return a list
of elements, allowing you to modify them if you wish. Usually you
will not notice this behavior, but beware of this:
printf("%s\n",end_form())
end_form() produces several tags, and only the first of them
will be printed because the format only expects one value.
> Perl snippet question:
>
[quoted text clipped - 21 lines]
> Yes I could just use a print statement. But I am kind of curious to
> why?
Szinger - 27 Sep 2007 22:45 GMT
> Perl snippet question:
[snip]
> This above code produces "<div></div></form>". This ti me is odd, since
> i only really want </form>. Does anyone have an explanation or another
> way to use the CGI.pm library and produce only </form>. Yes I could just
> use a print statement. But I am kind of curious to why?
You also see this with
$ perl -MCGI -le'print CGI::end_form'
<div></div></form>
$
According to the CGI.pm ChangeLog, this is a bug that was fixed in
3.12.
I think it has something to to with CGI.pm's sticky fields.
OSX 10.4 comes with CGI 3.05. My Linux box with CGI 3.15 doesn't have
this problem.