J
Jack
I am confused about how I can detect if the function jack has returned
an UNDEFined value;
note that I don't want to catch the return from 'jack' in a single
variable @array, rather I want it to return the seperate values, as
indicated.
Is there a way to detect if 'jack' returns undef (or null or
whatever), without first catching it in an @array variable.
The code below produces this:
$ perl test
defined(@array) is deprecated at test line 14.
(Maybe you should just omit the defined()?)
the return from jack() is 0, 3.14159, Lemmings, all of them!
$
but if I remove the 'defined' and change jack to return an 'undef', I
get this:
$ perl test
Useless use of private variable in void context at test line 8.
Useless use of private variable in void context at test line 8.
Useless use of private variable in void context at test line 8.
Use of uninitialized value in concatenation (.) or string at test line
16.
Use of uninitialized value in concatenation (.) or string at test line
16.
Use of uninitialized value in concatenation (.) or string at test line
16.
the return from jack() is , ,
$
////////////////////////////////////////////////////////////
use strict;
use warnings;
sub jack{
my $int1 = 0;
my $float1 = 3.14159;
my $string = "Lemmings, all of them!";
($int1, $float1, $string);
};
my $num;
my $flt;
my $str;
if( defined(($num, $flt, $str) = jack)){
print "the return from jack() is $num, $flt, $str \n";
}
else{
print "return was undef";
}
////////////////////////////////////////////////////////////
an UNDEFined value;
note that I don't want to catch the return from 'jack' in a single
variable @array, rather I want it to return the seperate values, as
indicated.
Is there a way to detect if 'jack' returns undef (or null or
whatever), without first catching it in an @array variable.
The code below produces this:
$ perl test
defined(@array) is deprecated at test line 14.
(Maybe you should just omit the defined()?)
the return from jack() is 0, 3.14159, Lemmings, all of them!
$
but if I remove the 'defined' and change jack to return an 'undef', I
get this:
$ perl test
Useless use of private variable in void context at test line 8.
Useless use of private variable in void context at test line 8.
Useless use of private variable in void context at test line 8.
Use of uninitialized value in concatenation (.) or string at test line
16.
Use of uninitialized value in concatenation (.) or string at test line
16.
Use of uninitialized value in concatenation (.) or string at test line
16.
the return from jack() is , ,
$
////////////////////////////////////////////////////////////
use strict;
use warnings;
sub jack{
my $int1 = 0;
my $float1 = 3.14159;
my $string = "Lemmings, all of them!";
($int1, $float1, $string);
};
my $num;
my $flt;
my $str;
if( defined(($num, $flt, $str) = jack)){
print "the return from jack() is $num, $flt, $str \n";
}
else{
print "return was undef";
}
////////////////////////////////////////////////////////////