nowox
nowox

Reputation: 29066

Display an error on STDERR and exit in Perl?

I currently implement my error display as below:

#!/usr/bin/env perl
error("Something happened");

sub error {say STDERR "Error: ", shift; and exit 1}

I am wondering if a better solution exists.

I don’t want to use die because the output with the traceback is sometimes too cryptic for basic users. I want a clean and simple message.

Actually I do the same with

sub verb {say STDERR "Info: ", shift;}
sub warning {say STDERR "Warning: ", shift;}

Upvotes: 1

Views: 167

Answers (1)

ikegami
ikegami

Reputation: 385546

die doesn't output a stack trace; it merely displays the line on which die is located, and even that can be omitted by ending the message with a line feed.

$ perl -e'die "foo\n"'
foo

Upvotes: 3

Related Questions