Rob,

As is you can't because Inline uses an INIT block to kickstart the
reading from the DATA handle, and INIT blocks are not run when you
"require" a file.

You need to modify data.pl in two ways for this to work:

1) replace __END__ by __DATA__ (I think __END__ works only in the main script)

2) Kickstart the Inline DATA processing manually by adding
Inline->init() as the first line of your script.

Here is a version that worked for me:

use warnings;
use Inline C;
Inline->init() ;

print multiply(3, 7), "\n"; # line 5

1;

__DATA__

__C__

int multiply(int x, int y) {
  return x * y;
}


Note: data.pl still seems to work if you run it by itself,
"Inline->init()" doesn't do
anything if it's called a second time.


Patrick


On Tue, Jan 25, 2011 at 10:03 PM, Sisyphus <sisyph...@optusnet.com.au> wrote:
> Hi,
>
> The demo:
>
> ##########################################
> C:\>type data.pl
>
> use warnings;
> use Inline C;
>
> print multiply(3, 7), "\n"; # line 5
>
> 1;
>
> __END__
>
> __C__
>
> int multiply(int x, int y) {
>   return x * y;
> }
>
> C:\>type try.pl
>
> use warnings;
> require 'data.pl'; # line 3
>
> C:\>perl try.pl
>
> Undefined subroutine &main::multiply called at data.pl line 5.
> Compilation failed in require at try.pl line 3.
> One or more DATA sections were not processed by Inline.
>
> C:\>
> ##########################################
>
> Does anyone here know how to get try.pl to work *without* rewriting data.pl
> so that it doesn't make use of the DATA section ?
>
> Cheers,
> Rob
>



-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada

Reply via email to