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

how can i get my program to stop saying died at line 23 i know it died there i told it to with die; but i would really prefer it to not spit that out.... how can i prevent that from occuring

Replies are listed 'Best First'.
Re: How to get die() to stop printing a line number?
by Elian (Parson) on Jul 01, 2003 at 19:35 UTC
    Reading the fine manual entry on die would tell you this, but if the die message ends in a newline (\n) then the "at file foo line bar" is supressed.
Re: How to get die() to stop printing a line number?
by KPeter0314 (Deacon) on Jul 01, 2003 at 20:42 UTC
    If you really want to write your own messages, die has a lot of flexibility. perldoc -f die describes how to use some of the built-in tokens to create them.

    From your comment of "i know it died there i told it to with die;" I would think you might be looking for exit instead. That just exits your program with a defined status code (or 0 if none is provided).

    -Kurt

Re: How to get die() to stop printing a line number?
by cfreak (Chaplain) on Jul 01, 2003 at 21:16 UTC

    Why do you want to? Die is for handling exceptions in your program. If you have a large program then the line number is extremely useful. If you just want your program to end, use exit instead.

    Lobster Aliens Are attacking the world!
      Strange. I usually am not interested at all on which line a program gave up and died. I want to know why it died. I generally don't care the program couldn't open a file on line 1273 - but I do care which file it couldn't open, and why.

      Abigail

        For me the question of where it died allows me to go there and start figuring out why it was doing what it did when it died. Therefore while where is in and of itself unimportant, it helps answer what I want answered.

        That's very foriegn to me. Say for instance I have a large program that has multiple files to open and I mistype a filename, either when I declare in some variable somewhere or even if I just used it in the open call itself. So now if I don't have a line number and the filename it spit back out was useless I have to go through the entire program to find where I made such a mistake. Even if its a variable that was declared elsewhere, the line number at least gives me a place to start. I may have forgotten the variable name I used, etc.

        For me an even more common use would be if a SQL query failed. Its extremely easy to have a syntax error in query, and it won't get caught until runtime. Sure I could print out the whole query and look for it, but a line number seems so much easier: fire up 'vim' <line-number> shift-G and there's the error.

        Lobster Aliens Are attacking the world!