in reply to The & prototype and code references in scalars.

I have this observation on when I read your post. First, the error I am getting seems to be different on my version, "perl 5.10.0 for MSWin32" when I run your code, I think the "not scalar dereference" or "not private variable" don't really reflect the same thing (that is debatable as I want to garner views on this from our revered monks).

A "variable" can be any one of the Perl variables we know of and in this case perl thinks it is supposed to be "private" -When I read your post I thought you were making a private subroutine to another subroutine- and which you just happened to not dereference as it should have been. Whereas a "scalar" is a sigil-preceded entity so in your case perl thinks you're passing a scalar dereference which might not be clear enough of a message !.

That's just an observation which I hope I can stand corrected and be clarified about.

#replicating the Origianl Post (strictures on): my $coderef = sub {print "Hi There \n";}; sub doit(&){ &{$_[0]}; } doit($coderef); #accessing a code ref from within a subroutine #Without prototype-check disabling..
#The same perl complaint is generated in the above code too C:\Documents and Settings\m>perl - sub testit{ print 'hi' };; sub doit (&) { $_[0]->() };; my $codeRef = \&testit;; doit( $codeRef );; __END__ Type of arg 1 to main::doit must be block or sub {} (not private varia +ble) at - line 4, near "$codeRef )" Execution of - aborted due to compilation errors.


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

Replies are listed 'Best First'.
Re^2: The & prototype and code references in scalars.
by BrowserUk (Patriarch) on Feb 18, 2010 at 15:25 UTC

    I didn't think that strictures or local versus global variables had, or could have any bearing on the matter. And in the great scheme of things it doesn't--other than the secondary diagnostic message.

    However, I think that your observation that the second part of the error message (not scalar dereference) (which I think is new from 5.10.0) is misleading, if not just plain wrong. In that what I was passing was a scalar containing a reference (to some code), not a dereference.

    But having seen the difference in the message you've received when the scalar containing the reference is a lexical, it suggests (perhaps), that the presence of the & prototype modifies what the code producing the message sees in some way.

    That is mildly confusing, but not hugely significant. As the messages identifying the source of the error are relatively new, perhaps they'll get honed as time goes on.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.