Re: What does *{"$callpkg\::$_"} = \&{"$pkg\::$_"} mean and how do I fix it?
- From: fxn@xxxxxxxxxxx (Xavier Noria)
- Date: Thu, 30 Jun 2005 11:45:02 +0200
[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
.
- Follow-Ups:
- Why XML not well formed?
- From: Nan Jiang
- Why XML not well formed?
- References:
- What does *{"$callpkg\::$_"} = \&{"$pkg\::$_"} mean and how do I fix it?
- From: Siegfried Heintze
- What does *{"$callpkg\::$_"} = \&{"$pkg\::$_"} mean and how do I fix it?
- Prev by Date: fork() and returning hash / strings to the parent - take2
- Next by Date: Why XML not well formed?
- Previous by thread: Re: What does *{"$callpkg\::$_"} = \&{"$pkg\::$_"} mean and how do I fix it?
- Next by thread: Why XML not well formed?
- Index(es):
Relevant Pages
|
|