Thank you all for the helpful replies. This code did it for me:

eval {$subset=$data->slice($b)->copy };
if ($@) {
    message "Wrong Slice string $@" ,mb::Error;
} else {
...


Ingo
On 08/21/2013 08:56 PM, David Mertens wrote:
> I'm not sure when a *bad* slice is caught, but an out-of-bounds slice
> is not caught until an actual evaluation. So, do a null operation,
> like adding zero in place. Note I use the eval { ... 1; } or do { ...
> }; idiom for exception handling, which I really like. It works just
> like a try/catch block, and is just as compact.
>
> my $slice;
> eval {
>     $slice = $data->slice($string);
>     $slice += 0;
>     1;
> } or do {
>     croak("Bad slice string $string");
> };
>
> This conflates a malformed string and an out-of-bounds error, which
> may or may not be what you want. But hopefully it's a start.
>
> David
>
>
> On Wed, Aug 21, 2013 at 2:49 PM, Luis Mochan <[email protected]
> <mailto:[email protected]>> wrote:
>
>     I believe you are missing quotes. The argument of eval is a string to
>     be compiled and executed, as in
>           eval ('$y=slice ($x,"0,8,,")')
>     Regards,
>     Luis
>
>
>     On Wed, Aug 21, 2013 at 02:14:14PM +0000, Chris Marshall wrote:
>     > I don't have a working PDL but I mean using
>     > eval for exception trapping.  Try looking at
>     > the eval docs in perldoc -f eval or someone with
>     > a working example....
>     >
>     > On Wed, Aug 21, 2013 at 1:51 PM, Ingo Schmid <[email protected]
>     <mailto:[email protected]>> wrote:
>     > > Chris,
>     > >
>     > > sorry, I get this. It never returns, just dies, apparently.
>     > >
>     > > pdl> help $x
>     > > This variable is Double D [2,6,1,4]            P            0.38KB
>     > > pdl> eval (slice ($x,'0,8,,'))
>     > >
>     > >
>     > > Runtime error: Stringizing problem: Slice cannot start or end
>     above
>     > > limit.    eval {...} called at Basic/Core/Core.pm.PL
>     <http://Core.pm.PL> (i.e. PDL::Core.pm)
>     > > line 2969
>     > >     PDL::string('PDL=SCALAR(0x4e242b0)', undef, '') called at
>     (eval 581)
>     > > line 5
>     > >
>     > >
>     > >
>     > > On 08/21/2013 03:36 PM, Chris Marshall wrote:
>     > >> eval ?
>     > >>
>     > >> On Wed, Aug 21, 2013 at 9:20 AM, Ingo Schmid <[email protected]
>     <mailto:[email protected]>> wrote:
>     > >>> Hi,
>     > >>>
>     > >>> I want a user to enter a string defining a slice of a piddle
>     to extract.
>     > >>>
>     > >>> Now when I call
>     > >>>
>     > >>>
>     > >>> $y=$x->slice($string) || barf "Not a valid slice\n";
>     > >>>
>     > >>> that does not catch it. How do I catch it?
>     > >>>
>     > >>> Ingo
>     > >>>
>     > >>> _______________________________________________
>     > >>> Perldl mailing list
>     > >>> [email protected] <mailto:[email protected]>
>     > >>> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>     > >>>
>     > >
>     >
>     > _______________________________________________
>     > Perldl mailing list
>     > [email protected] <mailto:[email protected]>
>     > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>     --
>
>                                                                       o
>     W. Luis Mochán,                      | tel:(52)(777)329-1734     /<(*)
>     Instituto de Ciencias Físicas, UNAM  | fax:(52)(777)317-5388    
>     `>/   /\
>     Apdo. Postal 48-3, 62251             |                          
>     (*)/\/  \
>     Cuernavaca, Morelos, México          | [email protected]
>     <mailto:[email protected]>   /\_/\__/
>     GPG: DD344B85,  2ADC B65A 5499 C2D3 4A3B  93F3 AE20 0F5E DD34 4B85
>
>
>
>     _______________________________________________
>     Perldl mailing list
>     [email protected] <mailto:[email protected]>
>     http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>
>
>
> -- 
>  "Debugging is twice as hard as writing the code in the first place.
>   Therefore, if you write the code as cleverly as possible, you are,
>   by definition, not smart enough to debug it." -- Brian Kernighan
>
>
> _______________________________________________
> 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