good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Check exist of anonymous subroutine before calling it within regexp substitute?by jffry (Hermit) |
on Oct 28, 2009 at 22:26 UTC ( [id://803816]=perlquestion: print w/replies, xml ) | Need Help?? |
jffry has asked for the wisdom of the Perl Monks concerning the following question: Either I was rather clever in the past or, more likely, I had cut-n-pasted code from someone smarter than me, I recently noticed that I am handling a log formatting string in my custom logging function using a hash of subroutine references. The relevant parts look something like this:
And $out_message is the what gets output. So if $log_format equals "%t %m", then the time is printed in front of each log message. The problem is that if $log_format contains a format character that does not exist (for example, "%X") in the %meta_char hash, then Perl does not like that at all. What I would like is if the code quietly ignored bad log formatting options, but how would I do that? The only thing I can think of is to add some sort of "if exists &sub" logic on the right side of that s// operation. However, Perl is not liking my attempts to do that. Any other ideas? Thanks much.
Back to
Seekers of Perl Wisdom
|
|