G
Gunnar Strand
Hi,
IANAPG (I Am Not A Perl Guru), but I found something which got me a
little worried. This has probably been discussed ad nauseum, but I
haven't found anything about it in the FAQ. sub's returning nothing
can be dangerous in some contexts. Consider this code:
#!/usr/bin/perl
use strict;
use warnings;
sub isok {
if ( $_[0] ) {
print "Ok\n";
} else {
print "Nok\n";
}
}
sub myvoid {
}
isok( myvoid(), 1 );
isok( ! myvoid(), 1 );
This script will print
Ok
Ok
and not any 'Nok'. I assume that's because 'nothing' is magically
removed from @_, leaving only the '1', right? I am trying out
the Test::Unit suite and had an empty sub in the code under test
while using assert in my test case, and all tests passed:
$self -> assert( $target -> the_test(), "Test OK" );
$self -> assert( ! $target -> the_test(), "Test NOK" );
IMHO, it would have been nice if perl could have issued some kind
of warning, since relying on 'nothing' as a return value seems...
well, not-so-common. Maybe perl is making heavy use of it internally?
Regards,
/Gunnar
IANAPG (I Am Not A Perl Guru), but I found something which got me a
little worried. This has probably been discussed ad nauseum, but I
haven't found anything about it in the FAQ. sub's returning nothing
can be dangerous in some contexts. Consider this code:
#!/usr/bin/perl
use strict;
use warnings;
sub isok {
if ( $_[0] ) {
print "Ok\n";
} else {
print "Nok\n";
}
}
sub myvoid {
}
isok( myvoid(), 1 );
isok( ! myvoid(), 1 );
This script will print
Ok
Ok
and not any 'Nok'. I assume that's because 'nothing' is magically
removed from @_, leaving only the '1', right? I am trying out
the Test::Unit suite and had an empty sub in the code under test
while using assert in my test case, and all tests passed:
$self -> assert( $target -> the_test(), "Test OK" );
$self -> assert( ! $target -> the_test(), "Test NOK" );
IMHO, it would have been nice if perl could have issued some kind
of warning, since relying on 'nothing' as a return value seems...
well, not-so-common. Maybe perl is making heavy use of it internally?
Regards,
/Gunnar