-----Original Message-----
From: Chris Nighswonger
Sent: Tuesday, April 09, 2013 6:39 AM
To: inline@perl.org
Subject: Re: Using Inline Python to import Python vars
So it does look as though the DATA splitting algorithm is a bit "loose."
In Inline.pm abt line 354:
@{$DATA{$pkg}} = split /(?m)(__\S+?__\n)/, $data;
shift @{$DATA{$pkg}} unless ($ {$DATA{$pkg}}[0] || '') =~
/__\S+?__\n/;
}
It appears we split on anything prefixed and suffixed with double
underscores.
A newline (immediately after the closing __) is also needed before any
splitting takes place:
######################
use warnings;
$data = "__DATA__ __C__ __other__ __Python__\n__version__";
@stuff = split /(?m)(__\S+?__\n)/, $data;
print ">>$_<<\n" for @stuff;
######################
Outputs:
__DATA__ __C__ __other__ <<
__Python__
<<
__version__<<
I can get the same type of failure with this (non-portable) Inline::C
script:
######################
use strict;
use warnings;
use Inline C => 'DATA';
foo();
1;
__DATA__
__C__
void foo() {
printf("%d %s\n",__MINGW32__
,"Hello");
}
######################
However, there's no problem at all if I rewrite foo() as:
void foo() {
printf("%d %s\n",__MINGW32__,
"Hello");
}
Thanks for digging this up, Chris !!
I don't personally use the "__DATA__" approach.
I'll do some digging myself right now, and see if I can come up with a
simple improvement to the regex.
(All the better if someone else beats me to it.)
As a quick guess, perhaps we split only if there's nothing other than
whitespace between the previous newline and the opening double underscore.
In the meantime, if (in Python) it's permissible to add whitespace at the
end of a line, then adding a space after __version__ should do the trick
methinks.
Cheers,
Rob