I thought the magic <> was worth mentioning specifically because of the error message issue, not because I thought people might not be able to figure it out.

When using the locale module and POSIX::setlocale, the error message does not seem to change. I get the same when setting LANG, LC_CTYPE, and LC_MESSAGES in my environment then using the locale module.

perllocale says this:

The remaining locale category, "LC_MESSAGES" (possibly supplemented by others in particular implementations) is not currently used by Perl--except possibly to affect the behavior of library functions called by extensions outside the standard Perl distribution and by the operating system and its utilities. Note especially that the string value of $! and the error messages given by external utilities may be changed by "LC_MESSAGES". If you want to have portable error codes, use "%!". See Errno.

There are options, though. You can use the Errno module to provide an error message in addition to the one Perl's going to emit, you can trap the warning and change the text that's emitted, or you can wrap the hash assignment/map/read in parentheses and use a logical or to emit an additional message.

use Errno; ... my %skater_avg = map { chomp; my( $skater, @scores ) = split /,/; { $skater => ( sum(@scores)-min(@scores)-max(@scores) ) / (@scores +-2) } } <>; warn "custom message!\n" if $!{ENOENT};
use Errno; $SIG{__WARN__} = sub { if ( $!{ENOENT} ) { warn "custom message!\n"; } };
( my %skater_avg = map { chomp; my( $skater, @scores ) = split /,/; { $skater => ( sum(@scores)-min(@scores)-max(@scores) ) / (@scores +-2) } } <> ) || warn "custom message!\n";

Update: made a doc link to Errno. Update 2:s/though/thought/ in that first sentence.


In reply to Re^4: winter games, perl, ice and bling by mr_mischief
in thread winter games, perl, ice and bling by mobiusinversion

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.