1. Perl
  2. builtin functions
  3. here

warn function - prints a warning

Use the warn function to output a warning . The line number where the warning was output is automatically added to the end of the message. To hide the line number, end it with a line break.

# Output warning

# With line number
warn $message;

# No line number
warn "$message\n";

What warn actually does is print a message to standard error. Same as the following print statement, except that it contains line numbers and raises the "__WANR__" signal. Warn may be used if you want to output a message to standard error even if it does not mean a warning.

# The meaning of warn is almost the same as the output to standard error output.
perl STDERR $message;

Catch the warning

You can catch the warning. When warn is executed, __WARN__ signal is generated, so catch this with the signal handler.

# Catch the warning

$SIG{__ WARN__} = sub {
    # Process you want to execute
};

warn "warning!";

Related Informatrion