Perl: How to "die" with no error message?
Asked Answered
R

5

7

I run a simple file test in perl with the code below:

my $f1 = "$pre_file";

 unless (-e $1) {

 print "\n Pre_check file does not exists! \n";

 die;

 } 

It prints the following output:

Pre_check file does not exists!
Died at ./huawei-postcheck line 81.

However I do not want the last line "Died at ./huawei-postcheck line 81.".

I want to to "die" with no error message.

Is it possible?

Rosco answered 19/10, 2011 at 11:5 Comment(0)
H
5

You could just say

die "\n";

to suppress the message.

Heliotaxis answered 19/10, 2011 at 13:33 Comment(0)
C
16

See the documentation for die.

If the last element of LIST does not end in a newline, the current script line number and input line number (if any) are also printed, and a newline is supplied.

So you can get die to work without printing anything by just using die "\n". But given that you have an error message, I can't see why you don't use that.

unless (-e $f1) {
  die "\n Pre_check file does not exist!\n";
}

Of course, the difference is that the message will now go to STDERR rather than STDOUT. But that's probably the right place for it to go.

Circumgyration answered 19/10, 2011 at 11:37 Comment(0)
M
9

use exit instead of die.

Millibar answered 19/10, 2011 at 11:7 Comment(1)
@Arkadiy, die actually uses $! || $?>>8 || 255, if you want to emulate it.Sandbank
A
6

You probably want to exit 1 instead of dying then.

Amoroso answered 19/10, 2011 at 11:7 Comment(0)
H
5

You could just say

die "\n";

to suppress the message.

Heliotaxis answered 19/10, 2011 at 13:33 Comment(0)
K
3
my $f1 = "$pre_file";

unless (-e $1) {
    print "\n Pre_check file does not exists! \n";
    exit 1;
}
Koren answered 19/10, 2011 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.