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

The following works for me in 5.16.0:
($die_on_error ? \&CORE::die : \&CORE::warn)->($error);

In 5.10.1, though, I am getting

Undefined subroutine &CORE::warn called

In older versions of Perl, you can still define your own subroutines and reference them (they can even be anonymous):

($die_on_error ? sub { die shift } : sub { warn shift } )->($error);

I do not find it more readable than

die $error if $die_on_error; warn $error;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Take reference and then dereference die() and warn()
by dmitri (Priest) on Nov 07, 2013 at 21:56 UTC
    Thanks! I forgot to specify perl version, it's updated now. It's good to know it works in later perls.