in reply to Need to Return() ?

wantarray

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Need to Return() ?
by a (Friar) on Mar 15, 2001 at 10:27 UTC
    And so others can get the benefit of your wisdom w/o the OOPerl book (but buy it nonetheless, its a great book), pg 34 gives the example:
    sub listdir { # do file listing and the: return @missing_files if wantarray(); return $listed_count if defined(wantarray()); carp "subroutine &listdir was called in a void context"; } # sub listdir
    The really cool thing here: wantarray returns true if:
    @missing = listdir(@files);
    (called in a list context); returns "" (i.e. false but defined) if:
    $list_count = listdir(@files);
    (called in a scalar context) and returns undef if:
    listdir(@files);
    (called in a void context - get the carp).

    a