On 5/26/2011 6:21 AM, Zeno Gantner wrote:

I am still new to PDL, and trying to get more comfortable with it.
So please excuse if my question is somehow naive ...

I found out that PDL::NiceSlice breaks calling function references.
Is this a known bug?

Yes, this is a known "feature" of the PDL::NiceSlice
implementation.  You can 'no PDL::NiceSlice' to turn
it off or you can work around the problem by using
&{ } to call subrefs.

--
#!/usr/bin/perl

use 5.10.1;

use PDL::NiceSlice;
my $fun_ref = sub { say $_[0]; };
&$fun_ref('Hey!');   # works
$fun_ref->('Hey!');  # does not work
--
... gives the output:
--
Hey!
Can't call method "nslice" on unblessed reference at ./pdl-niceslice.pl line 8.
--

By the way, PDL::NiceSlice is implemented as a Perl source filter,
what can be a bit dangerous.

I would not suggest blindly adding 'use PDL::NiceSlice'
at the top of arbitrary perl code.  However, for the
case of PDL code for computation, the NiceSlice syntax
is usually what you want and the specified workarounds
can be applied when needed.

What are the general recommendations towards PDL::NiceSlice? Is its
usage encouraged?

I use the NiceSlice syntax all the time in code that
I write myself since it allows PDL element operations
to look like "normal" matrix indexing.  If conflicts
with existing perl code was an issue, I would either
limit the PDL::NiceSlice to PDL computation sections
explicitly or use the slice() method.

Regards,
Chris

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

Reply via email to