in reply to Re: Why is @flds not imported?
in thread Why is @flds not imported?

What really puzzled me, is why the require in use Fields is not throwing an error.

And changing the name did indeed show a conflict. Turns out that the pragma fields (lowercase) comes with a bundled "class" (or whatever) Fields (capitalized) which is used.

C:\Windows\system32>corelist fields Data for 2013-01-20 fields was first released with perl 5.005 C:\Windows\system32>perldoc Fields NAME fields - compile-time class fields SYNOPSIS ...

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^3: Why is @flds not imported?
by perl-diddler (Chaplain) on Sep 25, 2017 at 02:46 UTC
    Why should 'use Fields' throw an error? It's included in the file.

    The copy of Fields in memory will have priority over the disk version with 'use mem'.

    Edit: Oh -- you are not talking about my version... nevermind.

      > Why should use Fields throw an error? It's included in the file.

      but not in %INC

      See require and perlvar#%25INC :

      > The hash %INC contains entries for each filename included via the do, require, or use operators. The key is the filename you specified (with module names converted to pathnames), and the value is the location of the file found. The require operator uses this hash to determine whether a particular file has already been included.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        But Fields had a "use mem".

        mem tells perl to use the in-memory copy of Fields (via adding it to the appropriate perlvar).

        I put a "use mem" inside any of my modules that need to be used in the same file. I also add a '1' at the end of the module, so if I later cut/paste the module out to a separate file, it shouldn't require modification.

        I also, often, use mem to insert "1-liner" BEGIN-needing assignments, as it looks a bit cleaner (IMOpinion), than equivalent the equivalent 1-liner using BEGIN{}. For multiple lines or, especially, when needing code, I tend more toward using an actual BEGIN block these days.

        I could use any module that ignores it's parameters for the same purpose, but mem guarantees it won't pay attention to their content, so its short and convenient. Ikegami used an equivalent assignment to some perlvar to do the same, but I often forget the var (or confuse it with INCLUDE), thus find mem easier to remember. :-| (*str8 face*)