Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for an undefined array 1

Status
Not open for further replies.

rvBasic

Programmer
Oct 22, 2000
414
0
0
BE
The following subroutine (pseudo code) can return an array or undef depending on validity checking of the input parameters;
Code:
sub rout{
my @Ar = $_[0]=~m/([\+-])?\s*([\d:]+),(\d{3}$)/;
#Some processing follows that results in either
# if valid parameters:
return (@Ar);
# or (if invalid)
return (undef);
}
But whatever I try in the main program the following test ALWAYS results as if the array was defined.
Code:
my $Br=();
@Br=&rout($SomeParm);
if (@Br){print "DEFINED\n";}
else {print "NOT DEFINED\n";}
if I replace the if (@Br) by if (defined(@Br)) then Perl is not happy and produces a message telling that defined has been depreciated.
However the following code does produce the desired result:
Code:
if (&rout($SomeParm)){@Br=&rout($SomeParm);print "DEFINED\n";}
else {print "NOT DEFINED\n";}
but at the expense if executing the sub twice.
How can I get what I want with one execution of the subroutine?

_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Yes, indeed. Thanks prex1, the star is yours!

_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top