in reply to Return Question in Subroutine

With apologies to Dr. Conway, I might write:
sub cleanup { return unless defined $_[0]; # remainder of code with no if around it. }
This gives back the undef the caller gave you (but in the proper context). As pointed out in earlier comments, that may not be what you want. To me this is sensible. It takes this routine out of the equation, leaving the caller to repair its own undefs.

I might also name the variable something. Some people would do something to make $_[0] into $_, so it doesn't have to appear on each line (but I'm not one of those people).

Phil

Replies are listed 'Best First'.
Re^2: Return Question in Subroutine
by Anonymous Monk on Apr 28, 2006 at 13:59 UTC
    So this is how it should be:
    sub cleanup { return unless defined $_[0]; $_[0]=~s/\'/\\\'/g; $_[0]=~s/<//g; $_[0]=~s/>//g; $_[0]=~s/;//g; $_[0]=~s/\(//g; $_[0]=~s/\)//g; $_[0]=~s/\"//g; $_[0]=~s/\'//g; $_[0]=~s/\?//g; $_[0]=~s/script//g; $_[0]=~s/\///g; $_[0]=~s/>//g; }