in reply to The & prototype and code references in scalars.
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.
|
|---|
| 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 |