Login | Register
My pages Projects Community openCollabNet

Discussions > users > Bitten by ProhibitExplicitReturnUndef

perlcritic
Discussion topic

Back to topic list

Bitten by ProhibitExplicitReturnUndef

Author hh10k
Full name Kurt Blackwell
Date 2013-10-24 02:04:39 PDT
Message 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"?

« Previous message in topic | 1 of 8 | Next message in topic »

Messages

Show all messages in topic

Bitten by ProhibitExplicitReturnUndef hh10k Kurt Blackwell 2013-10-24 02:04:39 PDT
     RE: Bitten by ProhibitExplicitReturnUndef hh10k Kurt Blackwell 2013-10-29 22:28:22 PDT
     Re: Bitten by ProhibitExplicitReturnUndef jonasbn Jonas B. Nielsen 2013-10-30 01:18:51 PDT
     Re: Bitten by ProhibitExplicitReturnUndef petdance Andy Lester 2013-10-30 06:27:22 PDT
         Re: Bitten by ProhibitExplicitReturnUndef rjray Randy J. Ray 2013-10-30 09:06:29 PDT
             Re: Bitten by ProhibitExplicitReturnUndef petdance Andy Lester 2013-10-30 09:10:39 PDT
     Re: Bitten by ProhibitExplicitReturnUndef thaljef Jeffrey Ryan Thalhammer 2013-10-31 12:46:26 PDT
         Re: Bitten by ProhibitExplicitReturnUndef thaljef Jeffrey Ryan Thalhammer 2013-10-31 12:54:24 PDT
Messages per page: