> -----Original Message-----
> From: "Stephan Tinnemeyer"<[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Date: Thu Sep 20 06:22:29 PDT 2001
> Subject: structure of scripts (newbie Q)
> 
> >I hope I did not overread this in the FAQ:
> >
> >In some tutorials I found the recommendation to put the code for
> >subroutines at the end of a script (i. e. after calling them) but it was
> >never explained why I should do so. I only see disadvantages:
> >
> >1. In my simple mind this would only make the interpreter jump through
> >the script which should not enhance the performance.
> >
> >2. Human beings have to jump through the script as well when they
> >attempt to understand how the script is working.
> >
> >Can somebody give me a clue of the advantages of this structure?
> >
> >TIA
> >
> >Stephan

Stephan,

For a concrete example, here's a bit of code from a script that I wrote:
---------------------------------------------
#!C:/perl/bin/perl.exe -w
# Please note that the taint switch (-T) is not used here as this is NOT
# a CGI program.  CGI.pm is merely used for its HTML generating functions.
use strict;

# This allows us to escape characters properly for query strings
use URI::Escape;

# This can be used to generate HTML character codes.
use HTML::Entities;

# Since this is a command line program, we don't want to be forced to
# enter name=value pairs.  Therefore, we use qw/:no_debug/
use CGI::Pretty qw/:no_debug/;
$CGI::Pretty::INDENT = "\t";

my $q           = CGI->new;

my $table_data  = create_table_data( $q );
my $source_code = read_source_code();
create_web_page( headers => [ 'Symbol', 'ASCII Value', 'URL encoded', 'HTML code' ],
                 data    => $table_data, 
                 code    => $source_code );
exit;
------------------------------------------------------------------

In this example, all of the relevant subroutines are included after this logic of the 
program.  As
you can see from the code above, you can get a decent idea of flow of control by 
having subs after
the main logic.

Some of the programs that I have worked with have had a bunch of initialization code 
at the top,
followed by a couple of thousand lines of subroutines, followed by the main logic 
buried at the
bottom of the script.  This was a pain to work with as it was not always immediately 
clear where
the main logic was.

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to