Hello Monks
I have a 'best practice' query. Suppose the simple script below. I want to (or maybe I don't!) create a module that might fail under certain circumstances. However, I would like to continue on from the calling script. I realise I could use 'return' but then I'd have to catch that value
So, with that in mind does anyone have any thoughts on how the package below might be rewritten to allow the calling script continue? I could also just print "SPLAT";return but I am unsure what the norm is.
You can see that I could use eval (commented out) but again, I am unsure of the best practice!?
#!/usr/bin/perl use strict; use Data::Dumper; my @r = (1..5); foreach (@r) { print "Start for $_\n"; my $splat = Splat->new(); #eval { $splat->splat() }; #if ($@) {next} if ($_ ==1) { print "Never getting this far\n" } } print "Nor this far\n"; package Splat; use Carp qw(croak); sub new { my $class = shift; my $self = {}; bless $self,$class; return $self; } sub splat { my $self = shift; croak "SPLAT!" if ! $self->{splat} } 1;
In reply to Croak, return et al. by packetstormer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |