Unitialized variables

B

Brad

Does anyone know a good test for an unitialzed variable? I tried
"! defined $var", but that doesn't seem to work. I've also tried
'$var eq ""' and that doesn't work either. Any suggestions would be
greatly appreciated!
 
A

A. Sinan Unur

(e-mail address removed) (Brad) wrote in
Does anyone know a good test for an unitialzed variable? I tried
"! defined $var", but that doesn't seem to work.

What do you mean it does not work? What do you expect and what happens
instead? Where is the code?

C:\Home> cat d.pl
my $var;
print "\$var is not defined\n" if ! defined $var;
print "\$var is not defined\n" unless defined $var;

C:\Home> cat d.pl
$var is not defined
$var is not defined
I've also tried '$var eq ""' and that doesn't work either.

my $var;
print "\$var is not defined\n" if '$var eq ""';

C:\Home> perl d.pl
$var is not defined

This last one underscores the importance of posting real code rather than
BS.
Any suggestions would be greatly appreciated!

Read the posting guidelines.

Sinan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top