Apr 19, 2002, 12:08 AM
Post #6 of 6
$I is a counter Yes! I used $I in the <OPTION value="$I"> line. The $I++ line increments the counter.
Re: [BrightNail] reading from Txt db to create form dropdown?
[In reply to]
About the [url=http://www.perldoc.com/perl5.6.1/pod/func/my.html]my statement:
You can use my() to declare a variable in a BLOCK. Using my() scopes the variable, so you can only use that in that BLOCK.
When you're not using my, every variable you use will be allocated in the package symbol table (%main:: for example) Perl uses the symbol table to keep track of all global variables, so they can be accessed through the entire program. In other words, memory is never freed or re-used, since the variable exists as global in the symbol table! Therefore, most Perl Programmers consider using my() a better coding style.
If you want to make a global variable anyway, you can use the [url=http://www.perldoc.com/perl5.6.1/lib/vars.html]vars pragma, or the [url=http://www.perldoc.com/perl5.6.1/pod/func/our.html]our statement as of perl v5.6.0.
The [url=http://www.perldoc.com/perl5.6.1/lib/strict.html]strict pragma forces declaration of all variables through my() in your .pl file. In that case, making a typoo in a variable name results in an error (and not a new global variable)
use strict; # forces declarations through my()
$x = 'fdfdsf'; # ERRORS: global symbol $x requires explicit package name
$x = 'fsdfdsfds'; # Now you can use $x
my $y = $x; # declare and assign a value
my($param1, $param2) = @_; # I love this Perl feature!!
print "PARAM1 = $param1, PARAM2 = $param2\n";
$param1 = 'fdfds'; # ERRORS! $param1 is not declared in this block, but in "sub dosomething()"
Yet Another Perl Programmer
~~> [url=http://www.codingdomain.com]www.codingdomain.com <~~
More then 3500 X-Forum [url=http://www.codingdomain.com/cgi-perl/downloads/x-forum]Downloads!