Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] View Source Code?????

Expand Messages
  • thehl1970
    Thank you, Charles. This is EXCELLENT feedback. With your comments and a fresh perspective I have reviewed my code. The print Start was a debugging statement
    Message 1 of 14 , Jul 4, 2005
    • 0 Attachment
      Thank you, Charles. This is EXCELLENT feedback. With your comments and
      a fresh perspective I have reviewed my code. The print 'Start' was a
      debugging statement I put in and never took back out. I needed someone
      else to see that one for me as this was probably half the problem.

      The other half appears to have been:

      print &StoreValues($Page);

      Which I'd cloned in clear stupidity as this is supposed to just store
      the values in an XML file and not return anything. Since I was
      printing the return value, which was probably a null, this was going
      out first in the HTML stream and probably causing my stupid problem.

      A submitter suggested I use HTML::Template, which I began doing, but
      it requires installation on the production system. I am writing
      shrink-wrap software and, so, choose to avoid this.

      Will CGI.pm require installation as well? With the cgi-lib.pl
      solution, I just copy that into my cgi-bin directory and I'm finished.

      I will review CGI.pm.

      Thanks again for all your counsel, advice, help.

      --- In perl-beginner@yahoogroups.com, "Charles K. Clarkson"
      <cclarkson@h...> wrote:
      > thehl1970 <> wrote:
      >
      > : I would appreciate any HELPFUL advice you may have. If there are
      > : things in my script you would like to suggest improvement on, I
      > : will be more than happy to listen to them.
      >
      > : #! /usr/bin/perl
      >
      > IMO, a good perl CGI script has warnings and strictures
      > turned on. Since you are using Apache 2.0, we can assume you are
      > also using a new version of perl. The "-T" on the command line
      > turns on taint checking.
      >
      > #! /usr/bin/perl -T
      >
      > use strict;
      > use warnings;
      >
      >
      > : # Global Variables:
      >
      > Good perl programming practices frown on the use of global
      > variables. Modern perl CGI scripts avoid global variables like the
      > plague. Just don't do this.
      >
      >
      > : require 'cgi-lib.pl';
      >
      > Modern perl CGI scripts use the CGI.pm module.
      >
      > use CGI '-noxhtml';
      >
      >
      > : print 'Start';
      >
      > This will not work through a server. You have not yet printed
      > the header. (Actually, it might work if cgi-lib.pl prints the
      > header automatically, but I doubt it.) You should be getting a
      > server error, not a program listing.
      >
      > Using the object oriented interface to CGI.pm, you would want
      > something like this. Read the CGI module documentation for
      > details.
      >
      > use CGI '-noxhtml';
      >
      > my $q = CGI->new();
      >
      > print
      > $q->header(),
      > $q->start_html('guestbook'),
      > $q->h1('Start');
      >
      >
      > : # Messages for later use
      > : %UsersMessages = ("UN_IDENT", "An un-identified error occured in:",
      > : "Back" , "Back");
      >
      >
      > With strictures enforced, global variables need to be file
      > scoped. Using single quotes, fat commas, white space, and lexical
      > variables we could do this.
      >
      > my %UsersMessages = (
      > UN_IDENT => 'An un-identified error occurred in:',
      > Back => 'Back'
      > );
      >
      >
      > : # Error codes
      > : $ERR_UN_IDENT=1024;
      >
      > You're not using this in the script.
      >
      >
      > : @date= localtime(time);
      > : @Months =
      > :
      >
      ('January','February','March','April','May','June','July','August','Septembe
      > r','October','November','December');
      > : $date[5] += 1900;
      > : $Time = "$date[3] $Months[$date[4]] $date[5]";
      >
      > These are also not used in this script. You might checkout the
      > POSIX function strftime(). It's interface is much easier to use
      > than this one.
      >
      > use POSIX 'strftime';
      >
      > my $Time = strftime( '%d %B %Y', localtime() );
      >
      >
      > : ###############################################################
      > : # This is main processing routine
      > : ###############################################################
      >
      > With the CGI module, this might look like this.
      >
      > if ( $q->param() ) {
      >
      > if ( $q->param('action') = 'something' ) {
      > # Do something.
      >
      > } elsif ( $q->param('action') = 'something_else' ) {
      > # Do something else.
      > }
      >
      >
      > } else {
      > # Do whatever is done when no form parameters are passed.
      > }
      >
      > The reason I mention NMS is because almost all of your script
      > is wrong. You are using programming practices that are dated or
      > unusual for modern perl. I don't know why your source code is
      > displaying in the browser, but I do know that this code is not a
      > good place to starting place for learning perl CGI programming.
      >
      >
      > HTH,
      >
      > Charles K. Clarkson
      > --
      > Mobile Homes Specialist
      > 254 968-8328
    • Charles K. Clarkson
      ... You might also look into CGI::Application which uses HTML::Template by default. HTML::Template is pure perl. There is no requirement to install pure perl
      Message 2 of 14 , Jul 4, 2005
      • 0 Attachment
        thehl1970 <> wrote:

        : A submitter suggested I use HTML::Template, which I began doing,
        : but it requires installation on the production system. I am
        : writing shrink-wrap software and, so, choose to avoid this.

        You might also look into CGI::Application which uses
        HTML::Template by default.

        HTML::Template is pure perl. There is no requirement to
        install pure perl modules. All you need to do to use it is to copy
        it to your cgi-bin directory in a sub directory named 'HTML'.

        Directories:

        /cgi-bin/
        myscript.pl

        HTML/
        Template.pm

        In myscript.pl use the 'lib' module to prepend the current
        directory ('.') to @INC, the array of directories that perl uses
        to find modules.

        use lib '.';
        use HTML::Template;


        : Will CGI.pm require installation as well? With the cgi-lib.pl
        : solution, I just copy that into my cgi-bin directory and I'm
        : finished.

        CGI.pm is a core module. It should be included in all modern
        perl installations. You might want to add the module locally like
        we did above to guarantee each installation is using the same
        version, but that is unlikely to be a problem.

        There is a decided advantage to using modules over the use of
        scripts like cgi-lib.pl. It only seems advantageous to use it now
        because you are not experienced with perl.


        : I will review CGI.pm.
        :
        : Thanks again for all your counsel, advice, help.

        You are welcome.

        HTH,

        Charles K. Clarkson
        --
        Mobile Homes Specialist
        254 968-8328
      • thehl1970
        Evidently, there is a requirement to install CGI.pm. If you run make install, it registers it s presence by modifying a file in the perl interpreter directory.
        Message 3 of 14 , Jul 4, 2005
        • 0 Attachment
          Evidently, there is a requirement to install CGI.pm. If you run make
          install, it registers it's presence by modifying a file in the perl
          interpreter directory. If you simply make the CGI.pm and do not run
          the install, the copy the CGI.pm file into the HTML directory, running
          a PERL program that accesses this generates an error. If you move it
          to the same directory as your script, same exact problem.

          I did not say that doing it cgi-lib.pl is simpler to code. I am a
          veteran software engineer and work hard to select the right solution
          for a given problem. If CGI.pm would have worked as you described it
          without modifying the existing system, I would have been happy to
          adopt this more modern solution.

          The problem is that, with shrink wrapped software being installed on
          web server, I do not have the luxury of modifying system files on the
          server. I must use what is there. While I'm sure you're right that 90%
          of professional web servers do not have this installed, supporting the
          other 10% will eat up all of the profits of my sale and significantly
          diminish my quality of work life.

          If you can lend a hand as to how to deploy CGI.pm along with my
          application without modifying system files, I will adopt this as my
          long-term solution. If not, though, I feel I must continue to use the
          older cgi-lib.pl approach, as ugly as it is.

          Thanks.

          --- In perl-beginner@yahoogroups.com, "Charles K. Clarkson"
          <cclarkson@h...> wrote:
          > thehl1970 <> wrote:
          >
          > : A submitter suggested I use HTML::Template, which I began doing,
          > : but it requires installation on the production system. I am
          > : writing shrink-wrap software and, so, choose to avoid this.
          >
          > You might also look into CGI::Application which uses
          > HTML::Template by default.
          >
          > HTML::Template is pure perl. There is no requirement to
          > install pure perl modules. All you need to do to use it is to copy
          > it to your cgi-bin directory in a sub directory named 'HTML'.
          >
          > Directories:
          >
          > /cgi-bin/
          > myscript.pl
          >
          > HTML/
          > Template.pm
          >
          > In myscript.pl use the 'lib' module to prepend the current
          > directory ('.') to @INC, the array of directories that perl uses
          > to find modules.
          >
          > use lib '.';
          > use HTML::Template;
          >
          >
          > : Will CGI.pm require installation as well? With the cgi-lib.pl
          > : solution, I just copy that into my cgi-bin directory and I'm
          > : finished.
          >
          > CGI.pm is a core module. It should be included in all modern
          > perl installations. You might want to add the module locally like
          > we did above to guarantee each installation is using the same
          > version, but that is unlikely to be a problem.
          >
          > There is a decided advantage to using modules over the use of
          > scripts like cgi-lib.pl. It only seems advantageous to use it now
          > because you are not experienced with perl.
          >
          >
          > : I will review CGI.pm.
          > :
          > : Thanks again for all your counsel, advice, help.
          >
          > You are welcome.
          >
          > HTH,
          >
          > Charles K. Clarkson
          > --
          > Mobile Homes Specialist
          > 254 968-8328
        • J.E. Cripps
          ... Umm, if you don t have CGI.pm isn t your perl out of date? Or something less than the standard installation? Complain to whoever _can_ modify the system
          Message 4 of 14 , Jul 4, 2005
          • 0 Attachment
            > If you can lend a hand as to how to deploy CGI.pm along with my
            > application without modifying system files, I will adopt this as my
            > long-term solution. If not, though, I feel I must continue to use the
            > older cgi-lib.pl approach, as ugly as it is.

            Umm, if you don't have CGI.pm isn't your perl out
            of date? Or something less than the standard installation?
            Complain to whoever _can_ modify the system files.

            perldoc perlmodlib

            lists the those that are standard, and CGI is one.

            perldoc CGI

            should yield the documentation that comes with CGI.pm

            There's much more; there are entire books about CGI.pm
          • thehl1970
            CGI.pm appears to be an add-in module as my version of perl is 5.8.5. I can t speak to whether it should have been included as it appears not to be. And you re
            Message 5 of 14 , Jul 4, 2005
            • 0 Attachment
              CGI.pm appears to be an add-in module as my version of perl is 5.8.5.
              I can't speak to whether it should have been included as it appears
              not to be.

              And you're missing the point about speaking to the person who can
              change the files. I am selling shrink-wrap software. I have no control
              over the site it will be installed on. It will be installed by the ISP
              customer on the ISP's server. If I make my package dependent on an
              "optional" (regardless of how standard) package, then I end up doing
              tech support and playing broker between my client and their tech
              support. I can't think of a faster way to diminish the pleasure of
              running my own software company.

              I would really like to use the latest and greatest technologies, but
              it appears to be intractable in this situation unless someone can
              counsel me on how it can be done.

              Thanks!

              --- In perl-beginner@yahoogroups.com, "J.E. Cripps" <cycmn@n...> wrote:
              >
              > > If you can lend a hand as to how to deploy CGI.pm along with my
              > > application without modifying system files, I will adopt this as my
              > > long-term solution. If not, though, I feel I must continue to use the
              > > older cgi-lib.pl approach, as ugly as it is.
              >
              > Umm, if you don't have CGI.pm isn't your perl out
              > of date? Or something less than the standard installation?
              > Complain to whoever _can_ modify the system files.
              >
              > perldoc perlmodlib
              >
              > lists the those that are standard, and CGI is one.
              >
              > perldoc CGI
              >
              > should yield the documentation that comes with CGI.pm
              >
              > There's much more; there are entire books about CGI.pm
            • J.E. Cripps
              ... so is mine. What happens when you try perldoc CGI ... True but CGI.pm has been Standard for quite a while, and your client really should have it. I
              Message 6 of 14 , Jul 4, 2005
              • 0 Attachment
                > CGI.pm appears to be an add-in module as my version of perl is 5.8.5.
                > I can't speak to whether it should have been included as it appears
                > not to be.

                so is mine. What happens when you try

                perldoc CGI

                > If I make my package dependent on an "optional" (regardless of how
                > standard) package, then I end up doing tech support and playing broker
                > between my client and their tech support.

                True but CGI.pm has been "Standard" for quite a while, and
                your client really should have it. I mean, there were
                "Porting cgi-lib.pl Scripts to CGI.pm"
                http://search.cpan.org/src/LDS/CGI.pm-3.10/cgi-lib_porting.html
                written in 1998. AIUI, it's been around as long as Perl 5.
              • Mike Southern
                LOL! You should check out the cpan archives. They are full of perl modules sometimes so riddled with dependencies that the five minutes it takes to actually
                Message 7 of 14 , Jul 4, 2005
                • 0 Attachment
                  LOL! You should check out the cpan archives. They are full of perl modules
                  sometimes so riddled with dependencies that the five minutes it takes to
                  actually perform the install is overwhelmed by the 3 hours it takes to find
                  the correct required modules.

                  That's a fact of perl development, it seems.

                  It also seems your 5.8.5 may be missing something; CGI.pm is part of the
                  standard package. Not optional.

                  If you are using something else, then your package should indicate this -
                  but before you do that I would seriously suggest that you find a machine
                  that *does* use cgi.pm and test your package against that.

                  If you are making an older function suite an install requirement, and there
                  is a conflict between old and new then you really won't have a customer
                  support problem at all; folk just won't use the software.

                  > I would really like to use the latest and greatest technologies, but
                  > it appears to be intractable in this situation unless someone can
                  > counsel me on how it can be done.

                  Not so sure it's latest and greatest. The module goes back to November 98.

                  http://search.cpan.org/~lds/CGI.pm-3.10/

                  I would counsel that you get yourself a fresh perl current download, install
                  it, and test your application using cgi.pm



                  On 7/4/05 7:08 PM, thehl1970 at thehl1970@... wrote:

                  > CGI.pm appears to be an add-in module as my version of perl is 5.8.5.
                  > I can't speak to whether it should have been included as it appears
                  > not to be.
                  >
                  > And you're missing the point about speaking to the person who can
                  > change the files. I am selling shrink-wrap software. I have no control
                  > over the site it will be installed on. It will be installed by the ISP
                  > customer on the ISP's server. If I make my package dependent on an
                  > "optional" (regardless of how standard) package, then I end up doing
                  > tech support and playing broker between my client and their tech
                  > support. I can't think of a faster way to diminish the pleasure of
                  > running my own software company.
                  >
                  > I would really like to use the latest and greatest technologies, but
                  > it appears to be intractable in this situation unless someone can
                  > counsel me on how it can be done.
                  >
                  > Thanks!
                  >
                  > --- In perl-beginner@yahoogroups.com, "J.E. Cripps" <cycmn@n...> wrote:
                  >>
                  >>> If you can lend a hand as to how to deploy CGI.pm along with my
                  >>> application without modifying system files, I will adopt this as my
                  >>> long-term solution. If not, though, I feel I must continue to use the
                  >>> older cgi-lib.pl approach, as ugly as it is.
                  >>
                  >> Umm, if you don't have CGI.pm isn't your perl out
                  >> of date? Or something less than the standard installation?
                  >> Complain to whoever _can_ modify the system files.
                  >>
                  >> perldoc perlmodlib
                  >>
                  >> lists the those that are standard, and CGI is one.
                  >>
                  >> perldoc CGI
                  >>
                  >> should yield the documentation that comes with CGI.pm
                  >>
                  >> There's much more; there are entire books about CGI.pm
                  >
                  >
                  >
                  >
                  > Unsubscribing info is here:
                  > http://help.yahoo.com/help/us/groups/groups-32.html
                  > Yahoo! Groups Links
                  >
                  >
                  >
                  >
                  >
                  >
                • Charles K. Clarkson
                  ... You need to read more about modules and installing modules. I named the directory holding Template.pm HTML because the module is named HTML::Template. Look
                  Message 8 of 14 , Jul 4, 2005
                  • 0 Attachment
                    thehl1970 <> wrote:

                    : Evidently, there is a requirement to install CGI.pm. If you run
                    : make install, it registers it's presence by modifying a file in
                    : the perl interpreter directory. If you simply make the CGI.pm
                    : and do not run the install, the copy the CGI.pm file into the
                    : HTML directory, running a PERL program that accesses this
                    : generates an error. If you move it to the same directory as your
                    : script, same exact problem.

                    You need to read more about modules and installing modules. I
                    named the directory holding Template.pm HTML because the module is
                    named HTML::Template. Look at the first line of that module.

                    package HTML::Template;

                    Since CGI.pm is not named HTML::CGI, perl will not look for it
                    in the HTML directory. It would look for it in the current
                    directory, which is probably /cgi-bin/.


                    : If you can lend a hand as to how to deploy CGI.pm along with my
                    : application without modifying system files, I will adopt this as
                    : my long-term solution. If not, though, I feel I must continue to
                    : use the older cgi-lib.pl approach, as ugly as it is.

                    In your case I would change the directory hierarchy to this.

                    /cgi-bin/
                    MyScript.pl

                    modules/
                    CGI.pm

                    CGI/
                    Util.pm

                    HTML/
                    Template.pm

                    In your scripts add the following near the top.

                    use lib 'modules';

                    Or (I didn't test):

                    use lib './modules';

                    In one IIS installation I use an absolute path.


                    The Util.pm module above is needed by CGI.pm. At the top of
                    that file is the following line. See how it works now?

                    package CGI::Util;


                    When using other modules mentally change the :: to / (or
                    whatever your directory separator is). Install them using this
                    directory structure.


                    HTH,


                    Charles K. Clarkson
                    --
                    Mobile Homes Specialist
                    254 968-8328
                  Your message has been successfully submitted and would be delivered to recipients shortly.