If you have a subroutine and you want to return "nothing" ...
But my questions in Re^2: reset particular variable were in the context of a discussion of differences between the  $var = (); and  $var = undef; et al statements, differences I still don't see.

WRT the examples you give in Re^3: reset particular variable, I realize now that what you mean by 'nothing' is 'an empty list'. I see the difference between returning an empty list and returning a list consisting of a single item that is undef (an undefined something).

Also WRT Re^3: reset particular variable, you say In Perl you can't even just exit a sub. But if you do an explicit  return; from a subroutine as opposed to an implicit return (i.e., falling off the end of the subroutine), then isn't the value returned always perfectly 'defined' semantically, dependent on the calling context of the subroutine? See examples below.

Other than documentary emphasis, is there any reason to prefer any of the other alternatves given below over a simple  return; statement? (Actually, I seem to recall that there exists an obscure case in which  return; and  return (); differ materially, but I don't have time right now to follow it up.)

>perl -wMstrict -le "sub Sr { return } sub Se { return () } sub Sw { return wantarray ? () : undef } print q{'}, Sr, q{' '}, join(q{' '}, 0+Sr, ''.Sr), q{'}; print q{'}, Se, q{' '}, join(q{' '}, 0+Se, ''.Se), q{'}; print q{'}, Sw, q{' '}, join(q{' '}, 0+Sw, ''.Sw), q{'}; " Use of uninitialized value in addition (+) at -e line 1. Use of uninitialized value in concatenation (.) or string ... '' '0' '' Use of uninitialized value in addition (+) at -e line 1. Use of uninitialized value in concatenation (.) or string ... '' '0' '' Use of uninitialized value in addition (+) at -e line 1. Use of uninitialized value in concatenation (.) or string ... '' '0' ''

In reply to Re^4: reset particular variable by AnomalousMonk
in thread reset particular variable by abubacker

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.