in reply to Check exist of anonymous subroutine before calling it within regexp substitute?
If it were my code, I'd probably write it the way moritz has it, but if you're extra paranoid, you might do something like this:
($out_message = $log_format) =~ s{%(.)}{ my $m = $meta_char{$1}; (ref sub {} eq ref $m) ? $m->() : $1 }ge;
That will withstand missing elements as well as elements that exist but don't have a code reference in them.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Check exist of anonymous subroutine before calling it within regexp substitute?
by jffry (Hermit) on Oct 29, 2009 at 17:25 UTC | |
by kyle (Abbot) on Oct 30, 2009 at 02:53 UTC |
In Section
Seekers of Perl Wisdom