stop a die();

Discussion in 'Perl Misc' started by lucas, Jan 28, 2004.

  1. lucas

    lucas Guest

    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();
    --
    lucas
    -------------------------
    Perl Coder since 2001
    shift || die;
    -------------------------
     
    lucas, Jan 28, 2004
    #1
    1. Advertising

  2. 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
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
     
    Tassilo v. Parseval, Jan 28, 2004
    #2
    1. Advertising

  3. lucas

    Anno Siegel Guest

    Michele Dondi <> wrote in comp.lang.perl.misc:
    > On Wed, 28 Jan 2004 02:17:44 -0500, lucas <> wrote:
    >
    > >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
     
    Anno Siegel, Jan 28, 2004
    #3
  4. lucas

    lucas Guest

    Thanks for both your answers. I think I have enough to fix my problem.
    ;)
    --
    lucas
    -------------------------
    Perl Coder since 2001
    shift || die;
    -------------------------
     
    lucas, Jan 28, 2004
    #4
  5. On Wed, 28 Jan 2004 02:17:44 -0500, lucas <> wrote:

    >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
    --
    you'll see that it shouldn't be so. AND, the writting as usuall is
    fantastic incompetent. To illustrate, i quote:
    - Xah Lee trolling on clpmisc,
    "perl bug File::Basename and Perl's nature"
     
    Michele Dondi, Jan 29, 2004
    #5
  6. On Thu, 29 Jan 2004 16:10:47 +0100, I wrote:

    > #!/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
    --
    you'll see that it shouldn't be so. AND, the writting as usuall is
    fantastic incompetent. To illustrate, i quote:
    - Xah Lee trolling on clpmisc,
    "perl bug File::Basename and Perl's nature"
     
    Michele Dondi, Jan 29, 2004
    #6
  7. On 28 Jan 2004 15:54:17 GMT, -berlin.de (Anno
    Siegel) wrote:

    >> 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
    --
    you'll see that it shouldn't be so. AND, the writting as usuall is
    fantastic incompetent. To illustrate, i quote:
    - Xah Lee trolling on clpmisc,
    "perl bug File::Basename and Perl's nature"
     
    Michele Dondi, Jan 30, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Theule

    Stop Debugging doesn't stop in ASP.NET

    Matt Theule, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    740
    Matt Theule
    Jul 24, 2003
  2. Lloyd Sheen

    Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    435
    Natty Gur
    Jan 26, 2004
  3. Lloyd Sheen

    More Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    453
    Alvin Bruney
    Jan 25, 2004
  4. Son KwonNam
    Replies:
    11
    Views:
    2,606
    mr_organic
    Apr 9, 2004
  5. Will
    Replies:
    1
    Views:
    15,249
    Thomas Weidenfeller
    Nov 2, 2004
Loading...

Share This Page