: my $a;
: my $b;
:
: $b = 10;
:
: if (defined $a){
All well and good; but in your original post (which I no longer have available to quote, but I believe I recall correctly), your $a (or equivalent) was the result of a substr operation. So it has, in fact, been assigned a value (the desired portion of the string). What you *want* to test is if that portion is the zero-length string, hence the length() function is what you need in this case.
Defined is for cases where nothing has actually been assigned, such as when a regex fails (or doesn't have enough matches to fill all the variables, or one alternation is chosen over another):
/("[^"]*")|(.*)/;
if (defined($1)) { #strip the quotes
See?
Good luck,
Joe
==============================================================
Joseph P. Discenza, Sr.
Programmer/Analyst
mailto:[EMAIL PROTECTED]
Carleton Inc. http://www.carletoninc.com
574.243.6040 ext. 300 fax: 574.243.6060
Providing
Financial Solutions and Compliance for over 30 Years
From: [EMAIL PROTECTED] on behalf of lorid
Sent: Fri 7/22/2005 10:27
To: Chris Wagner
Cc: perl-win32-users
Subject: Re: help with defined and !not defined
Chris Wagner wrote:
>You want to check if it's null,
not if it's defined. Defined means that the
>variable exists.
You want something like if ($photo_year) {...}.
>
>At 01:48 PM
7/21/05 -0700, lorid wrote:
>
>
>>my $ARGV[0]
will sometimes be passed a string like this:nvIGRA with no
>>date at
end and sometimes with date nvIGRA200511
>>if it does not have date I
need to set it another way but cant get
>>syntax of
!defined
>>
>>
>
>
>
----------------------------------------
you
are right about I should test for null or length of value instead but
I found
the place where I got information that says that to be defined a
var must
have a value:
Beginnng Perl by Simon Cozens pg 123:
"We can test if a
variable is defined by.......
#!/usr/bin/perl
use strict;
#use
warnings;
my $a;
my $b;
$b = 10;
if (defined
$a){
print "a has a value.\n";
}
if (defined $b){
print "b has a value.\n";
}
#only prints b has a
value
_______________________________________________
Perl-Win32-Users
mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs