Tim -
I'm sorry that I never go into discussing how to created a stand-alone file
with PDL::PP code. The normal way to do this is to create a full
distribution, with ExtUtils::MakeMaker or Module::Build, and use that whole
framework to build, link, and install the code. If you're writing PDL::PP
code that you don't plan on using anywhere else, you should use Inline.
As to your specific goal, you're looking for Inline's bind function.
if ($my_condition) {
Inline->bind(Pdlpp => q{
pp_def('my_func',
....
);
});
}
else {
....
}
David
On Fri, Mar 9, 2012 at 11:47 AM, Tim Haines <[email protected]>wrote:
> Greetings, all.
>
> I just read through the sections of PDL::Book and PDL::Tutorial that cover
> PP, but I didn't see an example of conditional compilation of a pp_def. Is
> this even possible using PP::Inline given the way the __END__ and __Pdlpp__
> macros work? Is there a way to do this just using PDL::PP? I am uncertain
> how to use 'raw' PDL::PP since the examples from PDL::Book and
> PDL::Tutorial all use PDL::PP::Inline (unless I missed it!).
>
> [code]
>
> use PDL;
> use Inline qw(Pdlpp);
> my $cond = 0;
> my $pdl = null();
>
> # sometime later
> if ($cond)
> {
> $pdl->say_hi();
> }
>
> # at the end of the script
> if ($cond) # Perl generates an error here since it can't see the
> closing brace
> {
> __END__
> __Pdlpp__
> pp_def('say_hi',
> 'Pars' => 'a(n)',
> 'Code' => q{ printf("%s\n", "Hello, world!"); }
> );
> } <--- The Perl parser can't see this brace, and PP generates an error
> for unclosed brace.
>
> [/code]
>
> The principle reason I am looking for this functionality is to remove the
> overhead of generating/compiling/linking the xs definition of say_hi unless
> the function is actually needed at runtime.
>
> Many thanks.
>
> - Tim
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl