in reply to Re: Scalar and void subroutines
in thread Scalar and void subroutines

You're right; my description was iffy. What I meant was:

If called in void context, I am expecting a reference to be passed.
If called in scalar context, I am expecting... either, actually, but there must be a reference in void.

Sorry about that.

Replies are listed 'Best First'.
Re^3: Scalar and void subroutines
by GrandFather (Saint) on Nov 10, 2005 at 21:35 UTC

    So you could:

    sub name { die 'ref arg required in void context' if ! defined wantarray and ! +ref $_[0]; my ($arg) = @_; if (ref $arg) { $$arg = 'x'; return; } return 'x'; }

    as a check that you've got a ref param in void context.


    Perl is Huffman encoded by design.