I agree with Abigail that it definitely matters who's going to see this message. If it's going to show up in an error log, I just make sure it's a unique string that I can grep for easily, something like this:

foo or die "sorrow, pestilence, Notepad: $!$/";

As long as I don't use the same error string twice, it takes about two seconds to find the place where the problem is.

If it's an error message that an end user is going to see, I do something rather different...

open FOO, "<$foo" or fatalerror "Couldn't Read Foo: $!"; # and off in an include file somewhere I define... sub fatalerror { my $email = $ENV{SERVER_ADMIN}; use HTML::Entities; my $code = encode_entities(shift); my $fm = <<"FRIENDLYMESSAGE"; <p class=\"error\">Oops! I seem to have run into a problem! This is probably a bug in the software on this site, something that the webmaster needs to fix. If this problem persists, you can contact the webmaster at <a href="mailto:$email">$email</a> and report the problem. It might get fixed faster if you include the exact technical error code that follows. </p> <p class=\"error\">Technical Error Code: $code</p> FRIENDLYMESSAGE # And then I output a page containing $fm in the # usual fashion. }

This is for CGI, which in my case is the only kind of interface used for stuff that end users see, but you can imagine a similar sort of thing for GUI stuff.


;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print

In reply to Re: Perl Style: About error messges opening files by jonadab
in thread Perl Style: About error messges opening files by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.