in reply to Using a 'package' as a 'module', and choosing at runtime?
#!/usr/bin/perl -w my $pkg; BEGIN { if ( $^O =~ /dar/ ) { $pkg = \&mac::get_answer } elsif ( $^O =~ /sol/ ) { $pkg = \&sun::get_answer } elsif ( $^O =~ /aix/ ) { $pkg = \&aix::get_answer } else { die "unknown os." } }; print "answer is " . &$pkg() . "\n"; exit 0; package mac; sub get_answer { return "Apple" } package sun; sub get_answer { return "Sun" } package aix; sub get_answer { return "IBM" } __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Using a 'package' as a 'module', and choosing at runtime?
by hardburn (Abbot) on Oct 28, 2003 at 16:32 UTC | |
by blueflashlight (Pilgrim) on Oct 28, 2003 at 18:10 UTC |