in reply to Take reference and then dereference die() and warn()

Sorry, I might have missed something, but why would you need reference to die in the first place?

Can't you have simply something like this:

if ($error) { $die_on_error ? die : warn->($error); }
I guess it should work fine.

If not in your case, you could define a "my_die" function:

sub my_die{die "I died\d"}
and take a reference to my_die, or alternatively make it a coderef with something like this:
$my_die = sub {die};

Replies are listed 'Best First'.
Re^2: Take reference and then dereference die() and warn()
by dmitri (Priest) on Nov 08, 2013 at 15:46 UTC
    The reason is that I want to put this into the or:
    do_something() or ($die_on_error ? \&die : \&warn)->("error");

      But you simply don't need that: you can just die or warn in the usual way within your ternary operator, as you can see in the following Perl one-liners:

      $ perl -e '$die_on_err=shift; 0 or ($die_on_err? die "failed\n" : warn + "warning\n")' 1 failed $ perl -e '$die_on_err=shift; 0 or ($die_on_err? die "failed\n" : warn + "warning\n")' 0 warning

        I realize that; my error message is much longer than "failed", and I do not want to copy-and-paste it.