I think Matt has found a bug in PDL::AutoLoader and/or PDL::NiceSlice::perldlpp actually...... Yeah...

The code is it stands should work - and indeed _does_ work if you do a very simple:

 perldl> do 'test_read.pdl'
 perldl> test_read()

or, to use Matt's version:
perl -e 'use PDL; use PDL::AutoLoader; do "pdllib/test_read.pdl" ; test_read () ; '

which is essentially what PDL::AutoLoader (should) do.

I don't know where the bug is and don't really understand the interaction between Autoloader, 'do' and the data-handles so if anyone want to dig, do feel free.

As for a fix, I don't think there is anything except changes, either:

  a) Encapsulate the data with the function
or
b) Put the function definitions into a package and then use the full package reference for the DATA handle...


                                                Cheers,
                                                        J.


On 7 Mar 2007, at 17:19, Derek Lamb wrote:

Well, I've never made my own module before, so now you've just got me guessing. But if your module is called Foo, then does 'rcols *Foo::DATA' work? I'm just going on a statement in my book here that says "The __DATA__ token opens the DATA handle in whichever package is in effect at the time, so different modules can each have their own DATA filehandle, since they (presumably) have different package names."

Derek

Matthew Kenworthy wrote:

Hi Derek,

(CCed to Robert, who provided the same solution)

Thanks for the solution - however, the method doesn't seem to work if
you put the subroutine into a separate .pdl module.

Example file is test_read.pdl:
=== START test_read.pdl ===
sub test_read {
   use PDL;
   use strict;
   ($a, $b) = rcols *DATA;
   print $a, $b;
   return (1);
}
1;

__DATA__
1 2
3 4
5 6
7 8
=== END ===

trying this method gives:

home$ perl -e 'use PDL; use PDL::AutoLoader; &test_read();'
File *main::DATA not found

Is there some way I can tell the .pdl module that there's a main::DATA
handle further down in the script?

Thanks,

Matt




_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl


_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to