The following subroutine (pseudo code) can return an array or undef depending on validity checking of the input parameters;
But whatever I try in the main program the following test ALWAYS results as if the array was defined.
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:
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]
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);
}
Code:
my $Br=();
@Br=&rout($SomeParm);
if (@Br){print "DEFINED\n";}
else {print "NOT DEFINED\n";}
However the following code does produce the desired result:
Code:
if (&rout($SomeParm)){@Br=&rout($SomeParm);print "DEFINED\n";}
else {print "NOT DEFINED\n";}
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]