Help - Search - Member List - Calendar
Full Version: What does *{"$callpkg\::$_"} = \&{"$pkg\::$_"} mean and how do I fix it?
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Siegfried Heintze
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?

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



Thanks again,

Siegfried

Below is the full code. Line 65 is nearly the last line of code.

----------------------------------------------------------------------------
----------------------------------------------



sub import {

my $pkg = shift;

my $callpkg = caller($ExportLevel);



if ($pkg eq "Exporter" and @_ and $_[0] eq "import") {

*{$callpkg."::import"} = &import;

return;

}



# We *need* to treat @{"$pkg::EXPORT_FAIL"} since Carp uses it :-(

my($exports, $fail) = (@{"$pkg::EXPORT"}, @{"$pkg::EXPORT_FAIL"});

return export $pkg, $callpkg, @_

if $Verbose or $Debug or @$fail > 1;

my $export_cache = ($Cache{$pkg} ||= {});

my $args = @_ or @_ = @$exports;



local $_;

if ($args and not %$export_cache) {

s/^&//, $export_cache->{$_} = 1

foreach (@$exports, @{"$pkg::EXPORT_OK"});

}

my $heavy;

# Try very hard not to use {} and hence have to enter scope on the
foreach

# We bomb out of the loop with last as soon as heavy is set.

if ($args or $fail) {

($heavy = (/W/ or $args and not exists $export_cache->{$_}

or @$fail and $_ eq $fail->[0])) and last

foreach (@_);

} else {

($heavy = /W/) and last

foreach (@_);

}

return export $pkg, $callpkg, ($args ? @_ : ()) if $heavy;

local $SIG{__WARN__} =

sub {require Carp; &Carp::carp};

# shortcut for the common case of no type character

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

}

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

QUOTE
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 . "::" . $_

QUOTE
(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

Xavier Noria
[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:

QUOTE
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 . "::" . $_


QUOTE
(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

Nan Jiang
Hi all,

I encountered a really weird error while using perl script to search in a
big XML/RDF file (225MB) in CGI.

I don't know what's wrong with it as the script works perfectly with a
sample XML/RDF file (only 4K) which has the same format as the big one and
their only difference is the file size. I attached the error msg below for
your reference

Software error:
not well-formed (invalid token) at line 221, column 97, byte 12020 at
C:/Perl/site/lib/XML/Parser.pm line 187

I have searched through perl-xml Q&A's and it seems that I did't have
problems they listed such as incorrect quotations usage or incorrect
encoding notations. So pls could anyone offer some suggestions?

many many thanks,


P.S. the xml file looks like this but with hundreds of <Topic/>
<?xml version='1.0' encoding='UTF-8' ?>
<RDF>
<Topic r:id="Top/Arts/Movies/Titles/1/10_Rillington_Place">
<link r:resource="http://www.britishhorrorfilms.co.uk/rillington.shtml"/>
<link
r:resource="http://www.shoestring.org/mmi_revs/10-rillington-place.html"/>
<link
r:resource="http://www.tvguide.com/movies/database/ShowMovie.asp?MI=22983"/>
<link r:resource="http://us.imdb.com/title/tt0066730/"/>
</Topic>
</RDF>



nan


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.