Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^19: can't import using exporter

by chromatic (Archbishop)
on Mar 20, 2012 at 18:04 UTC ( #960611=note: print w/replies, xml ) Need Help??

in reply to Re^18: can't import using exporter
in thread can't import using exporter

Usually a simple alias BEGIN{ *var=\$DEBUG::var}; is what I remember working -- USED it TONS of times.
{ package DEBUG; our $var = 'foo'; } { package main; BEGIN { *var = \$DEBUG::var }; print "Var is $var\n"; } $ perl Variable "$var" is not imported at line 14. Global symbol "$var" requires explicit package name at +line 14. Execution of aborted due to compilation errors. $ perl -v This is perl, v5.8.9 built for x86_64-linux

(Hint: our scope in this example and still the mess of compilation time versus run time in your longer example.)

Replies are listed 'Best First'.
Re^20: can't import using exporter (third package)
by tye (Sage) on Mar 20, 2012 at 19:12 UTC

    I disagree with your hints. But, more importantly, they miss an important point:

    #!/usr/bin/perl -w use strict; { package DEBUG; our $var = 'foo'; } { package main; BEGIN { package Other; *main::var = \$DEBUG::var }; # ^^^^^^^^^^^^^ ^^^^^^ print "Var is $var\n"; } __END__ Var is foo

    It doesn't actually have to be a third package, just not the destination package. So you could also use, for example:

    BEGIN { package DEBUG; no strict 'vars'; *main::var = \$var };

    - tye        

Re^20: can't import using exporter
by perl-diddler (Hermit) on Mar 24, 2012 at 15:26 UTC
    I'm not sure I get your point.

    I'm not sure if you are trying to point at a solution or what?

    Does Exporter not work for variable names in 6.14? It's documented as supporting them in its pod/manpages, but putting the var in @EXPORT as '$var' and then importing it in another package, doesn't work either in 6.14.

    Does it work in your 5.8?

    package Debug; {use parent "Exporter"; our $var="foo"; our @EXPORT=qw($foo); } package main; {import Debug; print $var; }' Name "main::var" used only once: possible typo at -e line 10. Use of uninitialized value $var in print at -e line 10.
      Does it work in your 5.8?

      As you've written it, of course it doesn't work.

        I wondered why I got an extra warning in the cut down version...

        but that's what I get for cuttin down.... can't type straight. ;-)

        ok so export var and not it's contents...

        I get warning, but it appears to work.

        Ok... but that's what I have in the larger program. But that's not the error it puts out...

        > less #!/usr/bin/perl -w use strict; package _Debug;{ our $Filename2Fields = 1; our $HaltOnError = 2; our $DEBUG_OPS = 3; our @EXPORT=qw( Debug $DEBUG_OPS $Filename2Fields $Halt_on_Error); use parent 'Exporter'; sub Debug($$) { my ($what, $str)=@_; if ($what & $DEBUG_OPS) { print STDERR $str; } } } package Transcode_plug;{ import _Debug; sub get_fieldAR_from_filename($) { my $file=$_[0]; Debug($Filename2Fields,"get_fieldAR_from_filename($file)\n"); } } Transcode_plug::get_fieldAR_from_filename('dummy'); # vim: ts=2 sw=2 Ishtar:/Audio/scripts> Global symbol "$Filename2Fields" requires explicit package name at ./t line 16. Execution of ./ aborted due to compilation errors.

        But if I turn off strict and turn off warnings, it runs just fine.


        How is this not a bug in perl 5.14? Crying wolf is bad, we learned that in grade school.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://960611]
[Corion]: chacham: Oh, yes, reinstalling all the SDK versions and Gradle and whatnot, yes, even in the short time I used it (2 weeks?) I felt that pain
[chacham]: right now im editing the versions in the applications gradle file to use a version it wants. sheesh.
[Corion]: Ow, "but you're not supposed to do that" ;)
[chacham]: with google, you kinda just gotta do what it recomends.

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2017-03-29 08:06 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (344 votes). Check out past polls.