[tpm] how to conditional compile

Abram Hindle abram.hindle at softwareprocess.es
Fri Nov 27 11:35:40 PST 2009


There are many ways to do this, ranging from running eval to assigning a sub to
the glob.

You can assign to the glob:

*mysub1 = sub { .. };

If you want ``conditional compilation'' then you should look into require.
But I'm not sure that's what you want. Eval would be similar.

abram


On Fri, 27 Nov 2009, Fulko Hew wrote:

> I thought I was doing the right thing, but I can't get there from here.
> What I'd like to do is 'conditional compile'.  ie. define this set of
> subroutines if something, and a different set if something else.
>
> For example:
>
> BEGIN {
>  if (eval 'use AMODULE; 1") {
>    sub mysub1 { print "do something"; }
>    sub mysub2 { print "something else"; }
>  } else {
>    sub mysub1 { print "mysub1() is unsupported"; }
>    sub mysub2 { print "mysub2() is unsupported"; }
>  }
> }
>
> Or in otherwords... if the module isn't found, I'd like to stub out some
> routines.
>
> Ideas anyone?
> TIA
> Fulko
>


More information about the toronto-pm mailing list