esharris has asked for the wisdom of the Perl Monks concerning the following question:

Here is an excerpt on "warn".

If LIST is empty and $@ already contains a value (typically from a previous eval) that value is used after appending "\t...caught" to $@. This is useful for staying almost, but not entirely similar to die.

If $@ is empty then the string "Warning: Something's wrong" is used.

The following code ...

#!/usr/bin/perl -w warn; $@ = 'Huh?'; warn; warn '';
... gives the following output.
Warning: something's wrong at ./temp4.pl line 2. Huh? ...caught at ./temp4.pl line 5. Huh? ...caught ...caught at ./temp4.pl line 6.
I didn't expect the last line, because the LIST is NOT empty; it has an empty string. Is ('') considered an empty list or is the documentation unclear?

Replies are listed 'Best First'.
Re: warn documentation unclear
by diotalevi (Canon) on Dec 08, 2005 at 03:06 UTC
    The documentation is wrong. The empty string is not like an empty list but warn is treating them alike.
Re: warn documentation unclear
by TedYoung (Deacon) on Dec 08, 2005 at 15:37 UTC

    I learned something new today. Thank you. I didn't know that warn propagated $@. It looks like die does too!

    # Currently, I do this on occasion: do $file; die $@ if $@; # This seems like a better and shorter choice: do $file; die if $@;

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
Re: warn documentation unclear
by TedYoung (Deacon) on Dec 08, 2005 at 15:37 UTC

    I learned something new today. Thank you. I didn't know that warn propagated $@. It looks like die does too!

    # Currently, I do this on occasion: do $file; die $@ if $@; # This seems like a better and shorter choice: do $file; die if $@;

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)