stop a die();

L

lucas

Is there a way to stop a die(); statement?
So far I've found: $SIG{__DIE__} = sub { };
However, that I can't figure out anything to stop a die();
 
T

Tassilo v. Parseval

Also sprach lucas:
Is there a way to stop a die(); statement?
So far I've found: $SIG{__DIE__} = sub { };
However, that I can't figure out anything to stop a die();

Wrap the code that could potentially die() into a BLOCK-eval:

eval { die };
print "alive\n";
print $@ if $@;
__END__
alive
Died at - line 1.

Tassilo
 
A

Anno Siegel

Michele Dondi said:
Is there a way to stop a die(); statement?
So far I've found: $SIG{__DIE__} = sub { };
However, that I can't figure out anything to stop a die();
[...]

You can "stop" a die
by exiting the call before it is completed:
[...]

open my $fh, "<\000" or die $ARGV[0] && goto HEHE;

HEHE: print 'done!'


Are you saying that when "goto" happens, "die" has already started
executing? That is not so. Perl evaluates the arguments before the
call to die.

Anno
 
M

Michele Dondi

Is there a way to stop a die(); statement?
So far I've found: $SIG{__DIE__} = sub { };
However, that I can't figure out anything to stop a die();

You have already been given a good answer. But, I beg your pardon, to
me the expression "to stop a die()" is ambiguous. You can "stop" a die
by exiting the call before it is completed:

#!/usr/bin/perl -l

use strict;
use warnings;

no warnings 'uninitialized';
open my $fh, "<\000" or die $ARGV[0] && goto HEHE;

HEHE: print 'done!'

__END__

# ./die.pl
Died at ./die.pl line 7.
# ./die.pl 0
0 at ./die.pl line 7.
# ./die.pl 1
done!

Please note that I'm by no means a goto() fanatic, I'd say quite the
contrary indeed, and I do not want to encourage its use! That may well
have been a return() in a sub or a next or last in a cycle, the key
point being that, to me, "to stop" is related to something that has
already started and can well be stopped, as the example shows...


HTH,
Michele
 
M

Michele Dondi

#!/usr/bin/perl -l

use strict;
use warnings;

no warnings 'uninitialized';
open my $fh, "<\000" or die $ARGV[0] && goto HEHE;

HEHE: print 'done!'

__END__ [snip]
Please note that I'm by no means a goto() fanatic, I'd say quite the
contrary indeed, and I do not want to encourage its use! That may well

BTW: basically I used it by virtue of the cardinal virtue called
'lazyness', but my lazyness was not long-sighted for I could have
shown a better example with no more effort:

#!/usr/bin/perl -l

use strict;
use warnings;

{
no warnings 'uninitialized';
open my $fh, "\000" or die shift && last;
}

print 'done!';

__END__


Michele
 
M

Michele Dondi

open my $fh, "<\000" or die $ARGV[0] && goto HEHE;

HEHE: print 'done!'


Are you saying that when "goto" happens, "die" has already started
executing? That is not so. Perl evaluates the arguments before the
call to die.

D'Oh!

Yes... that is what I was saying! But of course it is not so: it's
obvious that the trick works exactly because the arguments are
evaluated before the actual call.

But you may interpret my words in the sense that since the arguments
are being put "into" the func and follow it, the mentioned trick
conveys the *psycological* feeling that it works by *stopping* a call
that has already *started*, doesn't it? And now, isn't this a pretty
feeble excuse/justification?!?
;-)


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top