in reply to When is "use module" not the same as require+import?

Answering your question in the title, not your real question (which Corion already answered accurately):

There's another difference which the documentation is silent about, and that's the version of the module:

$ perl -wle 'use CGI 100' CGI version 100 required--this is only version 3.15 at -e line 1. BEGIN failed--compilation aborted at -e line 1. $ perl -wle 'BEGIN { require CGI; CGI->import(100) };' # (no output)

From the documentation there's no obvious way to require a minimal version of a module (expect checking it manually, and die if it's not large enough).

Replies are listed 'Best First'.
Re^2: When is "use module" not the same as require+import?
by ikegami (Patriarch) on Sep 19, 2008 at 19:28 UTC

    There is an easy way.

    >perl -wle "BEGIN { require CGI; CGI->VERSION(100) };" CGI version 100 required--this is only version 3.15 at -e line 1. BEGIN failed--compilation aborted at -e line 1.

    Also, Exporter emulates this behaviour, so your code would have worked if CGI used Exporter.

    >perl -e"{ package Mod; $VERSION='3.15'; } Mod->import(100)" >perl -e"{ package Mod; $VERSION='3.15'; use Exporter; @ISA='Exporter' +; } Mod->import(100)" Mod version 100 required--this is only version 3.15 at c:/Progs/perl58 +8/lib/Exporter/Heavy.pm line 121.