http://qs321.pair.com?node_id=291670


in reply to To || or not to or and why.

my $RootDirectoryCanidate= shift() or return undef(); my $RootDirectoryCanidate= shift() || return undef();
The question is which one should I use to accomplish my requirement?

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:

sub method { return if @_ && !defined $_ [0]; my $root_directory_candidate = shift; ... }
Now, if you want to return right away if nothing is passed as well, make the first line in the method:
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