The question is which one should I use to accomplish my requirement?my $RootDirectoryCanidate= shift() or return undef(); my $RootDirectoryCanidate= shift() || return undef();
Neither. The both return undef if no argument is passed, or if the first argument is 0, "0", or the empty string. What I would do is:
Now, if you want to return right away if nothing is passed as well, make the first line in the method:sub method { return if @_ && !defined $_ [0]; my $root_directory_candidate = shift; ... }
return unless defined $_ [0];
Note that I didn't do "return undef". If you do that, and you call the sub in list context, it will return a *true* value (a one element list). But a return without arguments will return an empty list in list context, and undef in scalar context.
Abigail
In reply to Re: To || or not to or and why.
by Abigail-II
in thread To || or not to or and why.
by krisahoch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |