tom arnall wrote:
under 'use strict', how do you assign a value to a constant used only in a
subroutine, without doing the assignment with every execution of the sub',
and without making the constant a global variable. by constant i mean a
variable which never changes value throughout the script.
thanks,
tom arnall
north spit, ca
Perl has no true constants (except literal constants). Why is it so
important the this value be only inside a subroutine? By make it a 'my'
global, the variable is restricted to the file. If it is a configuration
parameter, it is better to place it at the beginning of your program so
it is easily found (and grouped by function). All my programs have this
structure:
#!/usr/bin/perl
# NAME -- description
# --------------------------------------
# Pragmas
use strict;
use warnings;
use lib "$ENV{HOME}/perllib";
# --------------------------------------
# Modules
use Data::Dumper;
use POSIX;
# --------------------------------------
# Configuration
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
$Data::Dumper::Maxdepth = 0;
# --------------------------------------
# Globals
# --------------------------------------
# Subroutines
# --------------------------------------
# Main
__END__
--
Just my 0.00000002 million dollars worth,
--- Shawn
"For the things we have to learn before we can do them,
we learn by doing them."
Aristotle
"The man who sets out to carry a cat by its tail learns something that
will always be useful and which will never grow dim or doubtful."
Mark Twain
"Believe in the Divine, but paddle away from the rocks."
Hindu Proverb
* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>