Re: Module to handle substitution in error messages?
- From: anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno Siegel)
- Date: 20 Nov 2005 01:46:45 GMT
John Bokma <john@xxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:
> Henry Law <news@xxxxxxxxxxxxx> wrote:
>
> > I've googled and CPAN'd for the answer to this one but all my queries
> > return either zero or a zillion irrelevant entries. Maybe someone here
> > will know the place to look, or alternatively confirm my suspicion that
> > what I'm looking for doesn't exist.
> >
> > In previous programming projects, using languages other than Perl, I
> > created a set of routines which managed the issuing of error messages.
> > In summary my program would issue a call (speaking Perl now)
> >
> > write_error_message(203,"foo","zurb failed",$zurb_rc);
> >
> > In some file stored separately the error messages would be defined, with
> > placeholders for the bits that would vary from one invocation to
> > another; perhaps (I used XML but that's not essential)
> >
> > <msg id="203" severity="5">
> > <text>Module %s encountered a '%s' error, rc=%s</text>
> > <explanation>Some text to guide interpretation</explanation>
> > </msg>
> >
> > Then on executing the call an error message would appear thus:
> >
> > 203-5 Module foo encountered a 'zurb failed' error, rc= ... etc
> >
> > Is there a Message::Parameterise module, or something?
>
>
> Yes, it's called sprintf / printf :-D.
>
> sub write_error_message {
>
> my ( $id, @params ) = @_;
>
> my ( $text, $explanation ) = look_up( $id );
>
> printf STDERR "$text\n", @params;
> printf STDERR "$explanation\n";
> }
Tiny correction: The last "printf" should rather be "print". While the
$text part appears to be a printf format, $explanation looks like it
might use "%" innocently.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
.
- Follow-Ups:
- Re: Module to handle substitution in error messages?
- From: John Bokma
- Re: Module to handle substitution in error messages?
- References:
- Module to handle substitution in error messages?
- From: Henry Law
- Re: Module to handle substitution in error messages?
- From: John Bokma
- Module to handle substitution in error messages?
- Prev by Date: Re: GD::Graph: How to invert Y axis
- Next by Date: Re: Checking if a value in one hash exists in another
- Previous by thread: Re: Module to handle substitution in error messages?
- Next by thread: Re: Module to handle substitution in error messages?
- Index(es):