in reply to Question perlcritic ProhibitExplicitReturnUndef

Perl::Critic, by default, attempts to enforce the content of Perl Best Practices. PBP is intended as a set of guidelines and suggestions to make you think about how you write your code and whether it can be improved upon, not as a set of ironclad commandments.

Therefore, Perl::Critic's warnings should also not be taken as strict rules that you must comply with.

Perl::Critic gives you an explanation of why it objects to return undef;. Use that explanation to determine whether it is appropriate for you to return undef; in this case or not.

Also note that the Perl::Critic explanation says, "The solution is to just use a bare `return' statement whenever you want to return failure." If your intent is to return an undefined value rather than to indicate failure, then there's no problem with your return undef;, is there? (In that case, I would advise adding a comment stating that this is the intent so that a future maintainer who subscribes to PBP doesn't break your code in an attempt to "fix" it. Mentioning in the sub's documentation that a return value of undef is not intended to indicate failure would also be wise.)

Replies are listed 'Best First'.
Re^2: Question perlcritic ProhibitExplicitReturnUndef
by mje (Curate) on Feb 06, 2009 at 16:57 UTC

    I know what perlcritic is and that it is not a set of ironclad commandments or a set of strict rules that you must comply with.

    My point was more to do with the perlcritic description of the problem than how to work around it, or document the way the real sub I was using did. I had felt it was too strongly pointing you in one direction that may not be right for you but on reading it again noting your bolded emphasis I suppose it is targeted to using undef for error reporting which my example was not doing.