Re: What does *{"$callpkg\::$_"} = \&{"$pkg\::$_"} mean and how do I fix it?



[Sent a few hours ago, but apparently lost somewhere. I resent it just in case.]

On Jun 30, 2005, at 4:21, Siegfried Heintze wrote:

I have the following line of code:

my $id = async { &PopulateIndustryCompanyJobs($sIndustryName, $nThread);
$qCompleted->enqueue($sIndustryName); }




It causes this error:

Prototype mismatch: sub main::async (&;@) vs (&) at c:/Perl/lib/ Exporter.pm
line 65.


Here is the line of source code from my ActiveState Perl distribution 5.8+:

  *{"$callpkg\::$_"} = \&{"$pkg\::$_"} foreach @_;



I have two questions:

(1) What the heck does that line of code do? We are assigning a reference of
a function in some package to a typeglob? What do all the {} do? What is the
\:: for? Why the quotes?



That line aliases subroutines in different packages using fully qualified names. To export a subroutine into another package Exporter.pm puts it in its symbol table using the *... = \&... idiom. See the section "Symbol Tables" of perlmod.


The "\::" is needed to put a literal "::" in the string because otherwise Perl thinks you mean

    $callpkg:: . $_

whereas what you want is

    $callpkg . "::" . $_


(2) Am I doing something wrong? My program seems to work. What should I
change?



The description in perldiag is

Prototype mismatch: %s vs %s
(S prototype) The subroutine being declared or defined had previ-
ously been declared or defined with a different function prototype.


I guess "async" is the one from Thread.pm, does that explanation ring any bell?

-- fxn


.



Relevant Pages

  • Re: What does *{"$callpkg::$_"} = &{"$pkg::$_"} mean and how do I fix it?
    ... Here is the line of source code from my ActiveState Perl ... To export a subroutine into another package Exporter.pm puts it in its symbol table using the *... ... Prototype mismatch: %s vs %s ...
    (perl.beginners)
  • Re: Questions about some Minix components
    ... your post is very good and now i understand how Minix scheduler ... The prototype is: ... DON'T remove the original div64u function ... Obviously your source code will be incompatible with the official ...
    (comp.os.minix)
  • Re: Side project
    ... but the source code is.. ... Well, first is magical constants: ... It allows for variation among individual enemies, ... suppose you take something out of the prototype at a later stage ...
    (rec.games.roguelike.development)
  • Re: [OT] Can I make a prototype Free and sell the final product?
    ... It'll be just a prototype. ... customer pays for its upkeep and customization, ... source code, it is you who they pay for your continued expertise to make ...
    (Debian-User)