Ask a Question related to PERL Beginners, Design and Development.
-
Dan #1
Import oddity
Hello,
Weird thing here:
I get a variable from a module via @EXPORT_OK
like so:
use Foo::Monkey '$howdy'; # import the variable $howdy
print $howdy;
Works perfect.
Now if I add strict->import; to my module's import function like so:
package Foo::Monkey;;
[ standard goodies cut]
use base qw(Exporter);
sub import { strict->import; }
our $howdy = 'Howdy';
our @EXPORT_OK = qw($howdy);
[rest of goodies cut]
Then the script gives me "Global symbol "$howdy" requires explicit
package name..." since I'm not using 'my' (because the module should be
Exporting it)
I really really want to keep strict->import but need to be able to use
@EXPORT_OK and friends like normal.
Any ideas why /what is happening and what I can do to have my cake and
eat it to? (IE Have my strict and Export it too)
TIA
Dan
Dan Guest
-
Date oddity in Acrobat, default page size oddity
Got two things driving me nuts. One, when I go to Save As a file, the file dats come up in the form like this: Saturday, July -2147483642, 41221,... -
pl/pgsql oddity
Hello everyone, When writing some serverside code I ran into an oddity that I managed to boil down to this: ... -
Toolbox oddity
Greetings All. Does anyone know why the toolbox icons and all the tool options along the top are solid black on some machines and not others, i've... -
CSS & Template Oddity
I have created an entire website based on a template. In the beginning, I linked the CSS into the template and created pages. As I was building... -
OE oddity
Greetings, I recently let a friend use my computer for a few minutes to send some e-mail and somehow they managed to mess things up somewhat. ... -
James #2
Re: Import oddity
On Feb 17, 2004, at 7:56 AM, Dan Muey wrote:
I think "add" is the wrong word here. You "replaced" the inherited
import() method.
sub import {
my $class = shift;
$class->SUPER::import(@_);
strict->import;
}
I believe that will fix it. Not 100% sure though. Never tried it. ;)
Hope that helps.
James
James Guest
-
Dan #3
RE: Import oddity
> On Feb 17, 2004, at 7:56 AM, Dan Muey wrote:
>
> I think "add" is the wrong word here. You "replaced" the inherited
> import() method.
>
>
> sub import {
> my $class = shift;
> $class->SUPER::import(@_);
> strict->import;
> }
>
> I believe that will fix it. Not 100% sure though. Never
> tried it. ;)
> [/ref]
I just tried it and no go. Any other thoughts anyone?
Simply put sub import { strict->import; } breaks Exporter's @EXPORT_OK functionality.
It does help, we're getting there! Thanks :)
Dan Guest
-
Steve #4
Re: Import oddity
Dan Muey wrote:
>
> I just tried it and no go. Any other thoughts anyone?[/ref]
The problem here is that Exporter::import() looks at the calling
package, which in this case is Foo::Monkey *itself*, not the user
of Foo::Monkey.
Try this (a more general solution):
sub import {
my ($class) = @_;
$class->export_to_level(2, @_);
strict->import;
}
Or this (simpler):
sub import {
strict->import;
goto &Exporter::import;
}
--
Steve
Steve Guest
-
Dan #5
RE: Import oddity
> >
> > I just tried it and no go. Any other thoughts anyone?[/ref]
>
> The problem here is that Exporter::import() looks at the
> calling package, which in this case is Foo::Monkey *itself*,
> not the user of Foo::Monkey.
> [/ref]
Makes sense, but it works without strict->import; in the package's sub import { }
Does that make sense? I'm stuck!
I tried both and no go. All is well (IE the thigns specified
are Exported to the script) if I do not have strict->import; (Which makes
the script act as if they had 'use strict;' in the script)
I think we're getting there but I am missing somethgin that is probably simple and obvious.
Thanks a bunch
Dan
Dan Guest
-
Steve #6
Re: Import oddity
Dan Muey wrote:
Did you "use strict" or "require strict" anywhere?
--
Steve
Steve Guest
-
Dan #7
RE: Import oddity
> Dan Muey wrote:
> strict->import; (Which makes
>
> Did you "use strict" or "require strict" anywhere?
> [/ref]
package Foo::Monkey;
use 5.006;
use strict;
use base qw(Exporter);
sub import {
strict->import; # makes script using package act as if it had done 'use strict;' itself
# @EXPORT_OK symbols are Exported ok if strict->import; is not here, even if
# I coment out use strict above and do not have use strict
# in the script using the package (which I never did all along
}
Any thoughts?
Dan Guest



Reply With Quote

