in reply to Using a 'package' as a 'module', and choosing at runtime?

You could do something like

#! perl -slw use strict; use warnings; package xtest::mac; sub get_answer{ 'Apple' } package xtest::sun; sub get_answer{ 'Sun' } package xtest::aix; sub get_answer{ 'IBM' } package xtest::win; sub get_answer{ 'Win' } package xtest; if( $^O =~ m[(dar|sol|aix|win)]i ) { ## Export to main for testing only. *main::get_answer = \&{"xtest::\L$1\E::get_answer"}; } else { die 'Unknown OS'; } 1;

Then

P:\test>perl -Mxtest -e"print get_answer()" Win

If you have lots of vaient subs, then you can put the platform specific packages in separate modules, use the standard export mechanism and require them from the base package and then call test::$1::export(); to get the exports into your package.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!