Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: can't import using exporter

by perl-diddler (Hermit)
on Mar 13, 2012 at 02:52 UTC ( #959224=note: print w/ replies, xml ) Need Help??


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

Okay... I commented out the Module stuff. I put in "BEGIN{import Debug;}"
Then I get:

Global symbol "$Filename2Fields" requires explicit package name at /Au +dio/scripts/cnvWav2Flac line 120. Global symbol "$Filename2Fields" requires explicit package name at /Au +dio/scripts/cnvWav2Flac line 128. Global symbol "$Filename2Fields" requires explicit package name at /Au +dio/scripts/cnvWav2Flac line 134. Global symbol "$Filename2Fields" requires explicit package name at /Au +dio/scripts/cnvWav2Flac line 138. Global symbol "$Filename2Fields" requires explicit package name at /Au +dio/scripts/cnvWav2Flac line 142. Global symbol "$Filename2Fields" requires explicit package name at /Au +dio/scripts/cnvWav2Flac line 146. Use of uninitialized value at /Audio/scripts/cnvWav2Flac line 154.
Then I had a laugh when I thought, just, *maybe*, the @EXPORTS needs to be in BEGIN too...
Global symbol "$abr" requires explicit package name at /Audio/scripts/ +cnvWav2Flac line 245. Global symbol "$cbr" requires explicit package name at /Audio/scripts/ +cnvWav2Flac line 245. Global symbol "$minbitrate" requires explicit package name at /Audio/s +cripts/cnvWav2Flac line 245. Global symbol "$preset" requires explicit package name at /Audio/scrip +ts/cnvWav2Flac line 245. Global symbol "$resample" requires explicit package name at /Audio/scr +ipts/cnvWav2Flac line 245. Global symbol "$lowpass" requires explicit package name at /Audio/scri +pts/cnvWav2Flac line 245. Global symbol "$downmix" requires explicit package name at /Audio/scri +pts/cnvWav2Flac line 245. Global symbol "$addid3v2" requires explicit package name at /Audio/scr +ipts/cnvWav2Flac line 245. Global symbol "$id3v2_only" requires explicit package name at /Audio/s +cripts/cnvWav2Flac line 245. Global symbol "$id3v2_only" requires explicit package name at /Audio/s +cripts/cnvWav2Flac line 245. Global symbol "%lame_vars_to_fields" requires explicit package name at + /Audio/scripts/cnvWav2Flac line 245. Global symbol "$best" requires explicit package name at /Audio/scripts +/cnvWav2Flac line 245. Global symbol "$catalog" requires explicit package name at /Audio/scri +pts/cnvWav2Flac line 245. Global symbol "$catalog_number" requires explicit package name at /Aud +io/scripts/cnvWav2Flac line 245. Global symbol "$CDDB" requires explicit package name at /Audio/scripts +/cnvWav2Flac line 245. Global symbol "$composer" requires explicit package name at /Audio/scr +ipts/cnvWav2Flac line 245. Global symbol "$discid" requires explicit package name at /Audio/scrip +ts/cnvWav2Flac line 245. Global symbol "$disc_number" requires explicit package name at /Audio/ +scripts/cnvWav2Flac line 245. Global symbol "$max_lpc_order" requires explicit package name at /Audi +o/scripts/cnvWav2Flac line 245. Global symbol "$exhaustive_model_search" requires explicit package nam +e at /Audio/scripts/cnvWav2Flac line 245. Global symbol "$qlp_coeff_precision_search" requires explicit package +name at /Audio/scripts/cnvWav2Flac line 245. Global symbol "$force" requires explicit package name at /Audio/script +s/cnvWav2Flac line 245. Global symbol "$replay_gain" requires explicit package name at /Audio/ +scripts/cnvWav2Flac line 245. Global symbol "$silent" requires explicit package name at /Audio/scrip +ts/cnvWav2Flac line 245. Global symbol "$totally_silent" requires explicit package name at /Aud +io/scripts/cnvWav2Flac line 245. Global symbol "$total_discs" requires explicit package name at /Audio/ +scripts/cnvWav2Flac line 245. Global symbol "$performer" requires explicit package name at /Audio/sc +ripts/cnvWav2Flac line 245. Global symbol "$publisher" requires explicit package name at /Audio/sc +ripts/cnvWav2Flac line 245. Global symbol "$best" requires explicit package name at /Audio/scripts +/cnvWav2Flac line 245. Global symbol "$exhaustive_model_search" requires explicit package nam +e at /Audio/scripts/cnvWav2Flac line 245. Global symbol "$replay_gain" requires explicit package name at /Audio/ +scripts/cnvWav2Flac line 245. Global symbol "$qlp_coeff_precision_search" requires explicit package +name at /Audio/scripts/cnvWav2Flac line 245. Global symbol "$totally_silent" requires explicit package name at /Aud +io/scripts/cnvWav2Flac line 245. Global symbol "$silent" requires explicit package name at /Audio/scrip +ts/cnvWav2Flac line 245. Global symbol "$force" requires explicit package name at /Audio/script +s/cnvWav2Flac line 245. Global symbol "$max_lpc_order" requires explicit package name at /Audi +o/scripts/cnvWav2Flac line 245. Global symbol "%flac_vars_to_fields" requires explicit package name at + /Audio/scripts/cnvWav2Flac line 245. Global symbol "$vp" requires explicit package name at /Audio/scripts/c +nvWav2Flac line 245. Global symbol "$vp" requires explicit package name at /Audio/scripts/c +nvWav2Flac line 245. Global symbol "$vp" requires explicit package name at /Audio/scripts/c +nvWav2Flac line 245. Global symbol "$name" requires explicit package name at /Audio/scripts +/cnvWav2Flac line 245. Global symbol "$op" requires explicit package name at /Audio/scripts/c +nvWav2Flac line 245. Global symbol "$data" requires explicit package name at /Audio/scripts +/cnvWav2Flac line 245. Global symbol "$op" requires explicit package name at /Audio/scripts/c +nvWav2Flac line 245. Global symbol "$vp" requires explicit package name at /Audio/scripts/c +nvWav2Flac line 396. Global symbol "$name" requires explicit package name at /Audio/scripts +/cnvWav2Flac line 396. Global symbol "$data" requires explicit package name at /Audio/scripts +/cnvWav2Flac line 396. Quantifier follows nothing in regex; marked by <-- HERE in m/? <-- HER +E :et/ at /Audio/scripts/cnvWav2Flac line 399.
I guess NOT!! Just by putting the EXPORTS statement in 'Debug' in BEGIN blocks, I get all that?! How does that happen, and why line 245? Ick!... well if it isn't important we can ignore this mess... but if that's considered normal error output in 5.14.2, no probs here... ;-)

BTW, the same error message happen if I take off the brackets following the package 'Debug', that enclose all of it's code. I put those around packages just to ensure their scope is local, but technically, the package statement should do that. But if I remove those brackets.. boom, same explosion as putting @EXPORTS in a BEGIN block, which, I don't think *should* be needed, (I *hope* not, or I have alot of errors to figure out! ), but when things you think are right don't work, you try 'other' things...


Comment on Re^4: can't import using exporter
Select or Download Code
Re^5: can't import using exporter
by chromatic (Archbishop) on Mar 13, 2012 at 05:31 UTC

    You're doing this the hard way.

    Put each module in a separate file. Use use. Things will magically just work, because that's how they were designed to work.

    To make things work your way, you'll have to declare our variables outside of the BEGIN block and then, within a BEGIN block, assign to them. You're going to have a hard time getting things to work by randomly adding braces and blocks and little bits of syntax.

      I don't want to put define class point{ my x; my y; }

      in a separate file.

      I have 5-10 line modules that if I put in a separate file will multiple my work by 100%...

      You don't split things to a separate file till at least 1000 in many cases, and I've seen manageable files in the 2-3k range, though 5k gets a bit unwieldy....

      I have programs with 10 modules in 300 lines, and I should break them into 30 line modules each just because perl is broken?

      So far every method that everyone "knows" works, doesn't in 5.14, and that one guy wants to claim 5.14 isn't broken (worse than 5.12 and 5.12 -- which were also broken in various ways)...

      It's not like I haven't reported multiple bugs/RFE's...Usually met with resistance about not wanting to change the established order for fear of breaking existing code -- but I've got code broken by every perl upgrade since 5.6. Before that -- virtually nada (at least in the 5.x series).

      I've been told on the perl-porters list that they way I am doing things should work just fine with import and such...

      yet no one here seems to be able to make it work either.

      Hopefully grandfather who's on that list will take note.

      If I have to break it into separate files, then the language is broken.

      packages are meant to be modular. They aren't. I complained and was told all I needed to do was use import.

      I keep running into new problems in each new vversion.

      (I have had some programs that worked in 5.12, but fail now in 5.14)...

      So I wanted to make sure I wasn't missing *some* solution, that would work - before I go and file another bug about .. well... not sure!...

      modules don't work?

      I wanted 'use module' not try to include a module if it was in the same file... I got thoroughly roasted for that idea... yet it is so simple, but my guess is they can't make it work.

      If it worked that way, then a package could be removed anytime, and it would work in a libdir the same as in program.

      But now...it doesn't even work at all.

      Sorry. Breaking apart a 800 line perl prog that was a 185 line shell script , into a 10-15 file perl monster is messed up.

      These are not standalone packages -- they are mutually dependent classes. You don't put such things with dependent functionality in multiple files or your development becomes a nightmare finding what file you are supposed to be in.

        Extraordinary claims require extraordinary evidence.

        So far, all you have shown are two snippets that don't compile and a huge program that you obviously did not care to cut down to the problem. I've reduced your program to the following, self-contained program and noted where I added BEGIN blocks to make all symbols appear in the order which use would make appear them in as well:

        #!/usr/bin/perl -w use 5.12.0; use warnings FATAL => 'all'; BEGIN { # Added this because that's how "use" works package Debug;{ use Exporter 'import'; our @EXPORT=qw( Debug $Filename2Fields); my %dop = ( Filename2Fields => 1, HaltOnError => 2, ); our $Filename2Fields= $dop{Filename2Fields}; our $HaltOnError = $dop{HaltOnError}; sub Debug($$) { my ($what, $str)=@_; print STDERR $str; } }; } BEGIN { # Added this because that's how "use" works package Transcode_plug;{ use strict; use Exporter 'import'; BEGIN { Debug->import() }; our @EXPORT=qw( album get_fieldAR_from_filename ); sub album {}; sub get_fieldAR_from_filename($) { my $file=$_[0]; Debug($Filename2Fields,"get_fieldAR_from_filename($file)\n"); } }; } package main; BEGIN { Transcode_plug->import; }; print "Main is running\n"; # Now see that even prototype parsing works properly: print "OK\n"; get_fieldAR_from_filename "Foo"; # vim: ts=2 sw=2

        It behooves you well to put more effort into making your findings reproducible, especially when nobody else seems to be able to reproduce your problem.

        Also, you may be interested in App::fatpacker, which packs a script and its modules into one monolithic file.

        I have programs with 10 modules in 300 lines, and I should break them into 30 line modules each just because perl is broken?

        Perl is working exactly as documented. There's at least one question a week here about how this all works, and every time the answer is the same.

        I wanted 'use module' not try to include a module if it was in the same file...

        How is that to work? Is the compiler to guess that subsequent code in the file will declare a package? Is the compiler to process the entire file once, looking for package statements, and only then start compiling the code?

        You don't put such things with dependent functionality in multiple files or your development becomes a nightmare finding what file you are supposed to be in.

        Sure I do, and I don't have these nightmare debugging problems you do.

        Just a raw guess: Your "version control system" is called copy or cp and it does not scale to more than one file per project. Do you still live in the 1960s? Learn about git and subversion, both will solve that problem, and both scale to more source files than you ever need to use. Welcome to the 21st century!

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://959224]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2014-09-21 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls