Depends on your routine really. So if you use undef to signal a problem 
but otherwise your routine returns piddles then a check like

    $res = func(...)
    if (!defined($res)) { ScREAM loudly}

should be useful.

To test for pdl-ness is easy in the case of simple piddles, you can just 
test on ref($pdl) eq 'PDL'. However that will break when subclassing so 
if this is important you better use isa - the typical Perl incantation 
would be something like

    if (blessed($pdl) && $pdl->isa('PDL'))  { Then be happy }

although if you are an optimist UNIVERSAL::isa($pdl, 'PDL') is fine too 
- it is used occasionally in the PDL code IIRC.

                        Cheers,
                             J.

Edward (Post Doc) Hyer wrote:
> With regular Perl subroutines, doing simple things, my habit had been
> for them to simply
> return;
> if something went wrong. This meant I could simply check whether the
> output was defined to determine of the routine had done its job, as is
> standard Perl SOP.
> 
> With routines that are supposed to return PDLs, this is trickier.
> 
> Basically, I'm having trouble finding a routine that I can use to sort
> PDLs and other output. If I test the output, it barfs "multielement
> piddle in conditional expression" if it gets a PDL. If I used nelem(),
> well, nelem(undef) == 1.
> 
> TMTOWTDY, but the other ways are definitely uphill from a simple ispdl()
> function that can test for PDLness. I can't believe there's no such
> function-- there must be!
> 
> Help me out,
> 
> --EJH.
> 
> _______________________________________________
> 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