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

Module name case typo silent failure

by Anonymous Monk
on Sep 19, 2019 at 19:05 UTC ( #11106401=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

From time to time I forget to camelcase "HiRes" and this happens:

perl -MTime::Hires=time -Wle 'print time'
1568918270

Of course it should be:

perl -MTime::HiRes=time -Wle 'print time'
1568918268.29395

Questions:

Why no warning for module name camelcase typos?
Why no warning for the failed import of time function from bogus module?

Same in scripts with strict and warnings...

Replies are listed 'Best First'.
Re: Module name case typo silent failure
by Corion (Pope) on Sep 19, 2019 at 19:36 UTC

    Perl modules/package names and the names of the files they are stored in don't need to match. And if no import method exists, use will not complain.

Re: Module name case typo silent failure
by LanX (Archbishop) on Sep 19, 2019 at 20:09 UTC
    It depends on the operating system or resp. file system.

    Your code creates a fatal error on Linux but (after adaption°) runs on Windows because the standard FS there is case-insensitive

    Linux:

    perl -MTime::Hires=time -Wle 'print time' Can't locate Time/Hires.pm in @INC

    Windows:

    C:\WINDOWS\system32>perl -MTime::Hires=time -Wle "print time" 1568923613

    use is a require + import at compile time

    BEGIN { require Module; Module->import( LIST ); }

    That is it does a require of Time::HiRes (case-insensitive finds Hires.pm ) but fails to call Time::Hires->import() (Perl is case-sensitive)

    Corion already explained that a missing ->import method doesn't create an error, and the typo'ed Module = package = Time::Hires has no ->import routine.

    One might argue that the non-existence of the package Time::Hires should raise an error, probably you should file an error with perlbug.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    °) QUESTION: Where did you test that code???

      ... file an error with perlbug.

      Having a case-preserving but case-insensitive file system is another wonderful feature of Windows. Perl tries to be OS-agnostic, but there's only so much a humble program can do. The fact that this problem has not been addressed so far suggests to me that it's very difficult or impossible to deal with in this particular OS. Can you think of a way?


      Give a man a fish:  <%-{-{-{-<

        > Can you think of a way?

        IMHO the problem is at another place.

        It's OK that ->import() is not required to exist inside a package (or let's say I doubt that this can be changed in a backwards compatible way).

        But trying to call a method on a non-existing package could fail. I.e. use could check if the MODULE-name exists in the right capitalization after require.*

        But for reasons that I do not understand yet does require auto-vivify the misspelled package.

        DB<7> require DaTa::DuMpEr DB<8> x grep {/dumper/i} %DaTa:: 0 'DuMpEr::' 1 *DaTa::DuMpEr:: DB<9>

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        *) or if it exists twice in different capitalizations.

      > One might argue that the non-existence of the package Time::Hires should raise an error, probably you should file an error with perlbug.

      not sure what is happening there, something creates the wrong namespace %Time::Hires:: after a require

      DB<1> x grep {/hires/i} %Time:: empty array DB<2> require Time::Hires DB<3> x grep {/hires/i} %Time:: 0 'HiRes::' 1 *Time::HiRes:: 2 'Hires::' 3 *Time::Hires:: DB<4>

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        The stash is created when parsing the require function. It doesn't even have to be run. This generally doesn't matter but can have an impact on things like indirect method calls.

        Existence of a stash isn't really a useful concept though. Too many things can lead to a stash existing, including loading a sub-package (loading Blurf::Guff would cause the Blurf:: stash to exist).

      Where did you test that code???
      
      perl -MConfig -le'print join" ",$],$^O,$Config{osvers}'
      5.028000 darwin 17.5.0
      
      
      Thank you for the thorough explanation.
        > 5.028000 darwin 17.5.0

        your FS must be case-insensitive then (?)

        > Thank you

        Your welcome! :)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: Module name case typo silent failure
by Anonymous Monk on Sep 20, 2019 at 09:13 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11106401]
Approved by dorko
Front-paged by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2019-10-21 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?