Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: Correct syntax for using $INC to keep modules in same file

by perl-diddler (Hermit)
on Jul 01, 2012 at 04:03 UTC ( #979283=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Correct syntax for using $INC to keep modules in same file
in thread can't import using exporter

But it wouldn't accomplish the same purpose. Besides, I only accept responsibility for the 'use mem' pragma.

The only purpose of specific line of code is to get around perl's inability to know when module Dbg has already been defined and, therefore, doesn't need to be searched for.

I'm using classes -- things without separate files, not modules -- which, being modular, do live in separate files. (Are we picking nits about definitions?, you say half-dozen, I say six, or such?)

So how does one tell Perl, in code that looks like perl code, and not some sort of assembler, that a 'use statement' should not go searching for files, but should use the 'in-memory' version instead? Note: BEGIN{} sticks out like a sore thumb. It doesn't fit with any other pragma.. so it doesn't qualify.

But I'm sure you love code like this:

{ package Parse_Options; # {{{1 use warnings; use 5.14.0; use mro; our (@ISA,@fields); use mem &{sub(){$::INC{'Parse_Options.pm'}=1}}; use mem &{sub(){our @fields = qw(quiet verbose numprocs ratio_jobs + srcX dstX); our @ISA = (qw(Data::Vars FileList + main)); }}; use Data::Vars \@fields,{quiet=>0,verbose=>0,ratio_jobs=>6/5};
In order for 'Data::Vars' to work correctly and in order for class inheritance to work at compile time, you have to have your fields (to Data::Vars, and Exporter -- similar problems) declared at 'BEGIN' time -- that's what mem does --- it forces the evaluation of it's args at BEGIN time.

For example, the use Data::Vars above has initialization args for the default values -- If I misspell or change any -- they are caught at compile time.

If you want the things you are importing with Exporter to by type-checked at compile time, you have to have them included at BEGIN time by using BEGIN or something like the above.

I don't remember it always being that way -- it seemed to be something that popped up in 5.12 or 5.14 -- and that was one of the major breakages I saw.

Another was putting use warnings/use strict; after every package statement --- not just once at the top of the file. I don't remember that being required before 5.14 or maybe 5.12 (my perl pretty much jumped from 5.10->5.14...)....I spent little time with 5.12...

You think stuff like the above drives you crazy??? I've just given up on perl making sense and decided to code around everything that doesn't make sense -- it was too much work trying to figure out the 'why's ... I could spend all my time doing that or getting something done.

As it stands, my Wave2Flac converter coverts 600MB Wave->300MB Flac with all optimizations in 8-10 seconds (of course it runs multiple jobs in parallel and uses a queue). Of course it's not really 'done' (want to add both Wav2mp3 & Flac2mp3...)... but that may be a while...dunno.

Previous working version was ~ 3-4 years ago, and then it took about 30-45 seconds/album.

My duplicate / outdated rpm code can sort through 13k rpms -- reading each via rpm, in a 2-phase parallel merge/sort -- <2 seconds. I'm not sure why the shell script version took multiple minutes...but it didn't run with 9-10 threads either.


Comment on Re^4: Correct syntax for using $INC to keep modules in same file
Download Code
Re^5: Correct syntax for using $INC to keep modules in same file
by Anonymous Monk on Jul 01, 2012 at 04:18 UTC
    Inheritance + Exporter = ClownShoes
Re^5: Correct syntax for using $INC to keep modules in same file
by chromatic (Archbishop) on Jul 01, 2012 at 06:53 UTC
    I don't remember it always being that way...

    You misremember. Perl 5 has worked that way for at least 12 years.

    I don't remember that being required before 5.14 or maybe 5.12...

    You misremember that too.

    I've just given up on perl making sense and decided to code around everything that doesn't make sense -- it was too much work trying to figure out the 'why's....

    The hows and whys have been in the documentation for years. Several people in this thread have tried to explain this to you. You will continue to struggle unless you decide to believe us.

    So how does one tell Perl, in code that looks like perl code, and not some sort of assembler, that a 'use statement' should not go searching for files, but should use the 'in-memory' version instead?

    You do so the same way you tell Perl that sort should load files and grep should shell out to Nethack. In other words, fundamental Perl 5 operations behave as they have been documented and implemented and tested and stable since the earliest versions of Perl 5.

    You are working against Perl and doing things the hard way and your problems reflect that. You have trouble debugging your code because you're doing things the hard way. Why are you continually asking for advice and ignoring that advice?

      You do so the same way you tell Perl that sort should load files and grep should shell out to Nethack.
      So you can't really say. That's why I listen but when told to leap over the cliff, I don't join the lemmings. When I asked that question on the p5p list, I was told "you don't", perl doesn't support using in-memory versions of modules, and we like it that way. It's not a matter of not being able to do it, it's religious zealotry.

      I'm not working against perl, I'm working against the tainted Koolaid. I know it can be better, and I know people are against it being better. My code doesn't work when I try to follow the manpages and manual -- when I go all quirky -- that's when my code works. I hate myself later, but I resolve to keep pushing for change. Usually, the changes I want come about -- but usually happen long after people have forgotten that I tried to push for them years earlier.

      I have trouble debugging my code? The reason I posted here was because perl claims to be UTF-8 compliant, but has a big whole in it's implementation -- in that it treats U+0-U-127 as Unicode, U+128-255 as Latin1, and U+256 and above as UTF-8. That's broken. That has nothing to do with the way I am programming.

      You didn't answer my questions you just continue to speak in riddles referring grep to using nethack while not answering how what I was doing was re-implementing modules and was not implementing same-file Classes that perl lacks?

      You seem to think perl doesn't change, but just looking at the changes from 5.10->5.12-- there was a change in isa -- it went from not working with inheritance to working;

      "object->isa('Foo') would report false if the package Foo didn't exist, even if the object's @ISA contained Foobject->isa('Foo') would report false if the package Foo didn't exist, even if the object's @ISA contained Foo.

      Bugs in autoload related to ISA were fixed, and autoload methods often didn't:"Various bugs in the new-to 5.10.0 mro code, triggered by manipulating @ISA, have been found and fixed.In the 5.10.0 release, a dynamically created AUTOLOAD method might be missed (method cache issue) RT #60220,60232."

      What works in perl in any given release changes. It's documented. You may believe it hasn't changed, but oh well.

      As for the previous anonidjit, knowing when to Export and when to make something a class is a sign of knowing your tools. Always using the same methodology for each problem is... a sure way to obsolescence.

        That's why I listen but when told to leap over the cliff, I don't join the lemmings.

        How dare you insult the poor lemmings by implying you're somehow smarter?

        (method cache issue) RT #60220,60232."

        What works in perl in any given release changes. It's documented. You may believe it hasn't changed, but oh well.

        You code contained no such dynamic classes where caching/AUTOLOAD was an issue -- Your problem was basic misunderstanding of compile phases and of syntax

        I was told ... perl doesn't support using in-memory versions of modules.

        Nonsense.

        You have been told repeatedly in this thread that the semantics of the order of operations of bareword checking and importing have been long established and documented and tested and unchanged for years. You have been given several suggestions as to how to fix your problem.

        Download any of several dozen of releases of Perl and try the various examples multiple people have given you in this thread. It's easy. It's empiricism.

        You seem to think perl doesn't change...

        I'm not interested in helping you if you're going to put strawmen arguments in my mouth.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-07-30 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (240 votes), past polls