That doesn't do what you expect. The second use Foo::Bar gets executed first, and it gets executed unconditionally.
Why would you want to fallback to the same module anyway? That's the same as not putting a version in the first place! If you wanted to fallback to a different module, the following will do:
BEGIN { my $module = 'Foo::Bar'; require Foo::Bar; eval { Foo::Bar->VERSION(5.01) }; if ($@) { warn(...); $module = 'Foo::Baz'; require Foo::Baz; } import $module qw( ... ); }
VERSION is documented in UNIVERSAL.
In reply to Re^2: BEGIN and compile-time
by ikegami
in thread BEGIN and compile-time
by jbert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |