=over =item warn LIST X<warn> X<warning> X<STDERR> Emits a warning, usually by printing it to C<STDERR>. C<warn> interprets its operand LIST in the same way as C<die>, but is slightly different in what it defaults to when LIST is empty or makes an empty string. If it is empty and L<C<$@>|perlvar/$@> already contains an exception value then that value is used after appending C<"\t...caught">. If it is empty and C<$@> is also empty then the string C<"Warning: Something's wrong"> is used. By default, the exception derived from the operand LIST is stringified and printed to C<STDERR>. This behaviour can be altered by installing a L<C<$SIG{__WARN__}>|perlvar/%SIG> handler. If there is such a handler then no message is automatically printed; it is the handler's responsibility to deal with the exception as it sees fit (like, for instance, converting it into a L<C<die>|/die LIST>). Most handlers must therefore arrange to actually display the warnings that they are not prepared to deal with, by calling L<C<warn>|/warn LIST> again in the handler. Note that this is quite safe and will not produce an endless loop, since C<__WARN__> hooks are not called from inside one. You will find this behavior is slightly different from that of L<C<$SIG{__DIE__}>|perlvar/%SIG> handlers (which don't suppress the error text, but can instead call L<C<die>|/die LIST> again to change it). Using a C<__WARN__> handler provides a powerful way to silence all warnings (even the so-called mandatory ones). An example: # wipe out *all* compile-time warnings BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } } my $foo = 10; my $foo = 20; # no warning about duplicate my $foo, # but hey, you asked for it! # no compile-time or run-time warnings before here $DOWARN = 1; # run-time warnings enabled after here warn "\$foo is alive and $foo!"; # does show up See L<perlvar> for details on setting L<C<%SIG>|perlvar/%SIG> entries and for more examples. See the L<Carp> module for other kinds of warnings using its C<carp> and C<cluck> functions. =back