in reply to Re^2: winter games, perl, ice and bling
in thread winter games, perl, ice and bling

Thank you for your comments.

they should probably be the same.

I am of the "do what looks right in each individual situation" school of thought, which I believe is very consistent with the Perl philosophy.

perhaps worth mentioning is the magic <>.

Um... I think not. It's Perl 101.

in the case of internationalization it might pose an issue.

Really? Is perl's default error message library not sufficiently internationalized?

A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re^4: winter games, perl, ice and bling
by mr_mischief (Monsignor) on Mar 27, 2008 at 16:19 UTC
    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.