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


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.