in reply to Conditional use of 'use'

Since use module is the same as
BEGIN { require module }
, you could do something like:
BEGIN { my $version = (($0 =~ /2(?:\.pl)?$/) ? '2' : ''); require "LayerB${version}.pm"; }
If you are using the form use module LIST you'll need to call import:
BEGIN { # set $version based on $0 require "LayerB${version}.pm"; "LayerB${version}"->import(qw(A B C)); }

update: added import part, cleaned up $version setting

Replies are listed 'Best First'.
Re: Re: Conditional use of 'use'
by dvergin (Monsignor) on Jun 12, 2001 at 09:08 UTC
    Camel 3, p. 822 (which I had already consulted), says: BEGIN { require MODULE; import MODULE LIST; } What about the import? Needed? Not? The modules are pure OO. And no @EXPORT (if that is relevant).
      You've asked the right question. If you only ever use the OO interface and if you don't export anything from the modules, you don't need to import anything explicitly.

      Then you can just do:

      if ($version == 2) { require LayerB2; } else { require LayerB; }

              - tye (but my friends call me "Tye")