in reply to constant variable using scaler variable
Alternatively, set up a hash with your error messages:
use strict; use constant ERR => 'Some error happened.'; use constant OK => 'All is fine.'; my %messages = ( 'ERR' => ERR(), 'OK' => OK(), ); my $res = some_func(); print $messages{ $res }, "\n";
Alternatively, you can invite the demons of symbolic references into your house, but they will eat your children:
use strict; use constant ERR => 'Some error happened.'; use constant OK => 'All is fine.'; my $res = some_func(); { no strict 'refs'; print &$res(), "\n"; };
|
|---|