At 22:19 06.06.2001 -0700, you wrote:
> > I am also not using my $var=""
> > because my cgi class did not teach me how and I haven't found the
> > time to incorporate my knowledge from my recently-taken Intro to Perl
> > class. Some pontification on the usage my $var="" would be great.
> > As well as the appropriate usage of "&&" and "and" and "||" and "or".
If they didn't hammer home the importance of using strict in your Perl
class, I'd ask for my money back. If you use strict, then you have to use
my, and you save yourself a lot of possible problems.
You want to make sure that when you declare a variable, you only use it in
the scope that you need it for, otherwise, if you use the same variable
name somewhere else in your program, you might not get what you expect out
of it.
The use of my makes sure that when the program leaves a block of code, the
variable dies and can't pollute the rest of the program.
example:
if(1 == 1)
{
$text = "hello";
...
}
here, $text is visible to the rest of the program, and if you use $text in
another part of the program, it may still contain "hello", which may or may
not be what you want.
if(1 == 1)
{
my $text = "hello";
...
}
now, as soon as I'm out of the if loop, $text disappears. If I use $text
elsewhere, I know I'm getting a clean, empty variable.
if you put this:
use strict;
at the top of your perl script, the use of my will be required when you
declare a variable. Play around with it and see how much it helps you keep
your program in order -- it also helps find typos :)
Aaron Craig
Programming
iSoftitler.com