Subject: | Bitten by ProhibitExplicitReturnUndef |
Date: | Thu, 24 Oct 2013 02:04:39 -0700 (PDT) |
To: | users [...] perlcritic.tigris.org |
From: | Kurt Blackwell <kurt [...] blackwell.id.au> |
Hi all,
I'm still adapting my code to some of Perl::Critic's nagging, and one that is causing me some problems is ProhibitExplicitReturnUndef. 99% of my functions either will return a list or a scalar, but never both. However ProhibitExplicitReturnUndef encourages you to return empty lists from scalar functions which often causes me dramas.
eg:
sub get_value {
open my $file, '<', 'source.txt' or return;
my $result = <$file>;
close $file;
return $result;
}
my %hash = (
a => get_value, # Bug!
b => 1
);
print substr(get_value, 3), "\n"; # Bug!
Is there a alternative to ProhibitExplicitReturnUndef that only complains when mixing scalar and list return values, rather than telling me off for a perfectly deliberate "return undef"?
------------------------------------------------------
http://perlcritic.tigris.org/ds/viewMessage.do?dsForumId=4232&dsMessageId=3066959
To unsubscribe from this discussion, e-mail: [users-unsubscribe@perlcritic.tigris.org].