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

I was going through perlfunc alphabetically yesterday (doesn't everyone? :) and I came across the description of die. Much to my surprise it takes a LIST not an EXPR. At first I thought this was a typo but I tested it with

die ( 'foo' , 'bar' , 'baz' );
and I do get foobarbaz.

I've never seen anyone give die a list and the examples in perlfunc all use single scalars. Since die just sends it's argument to STDERR, of what use is giving it a LIST. I note also that warn is the same. Is this for people who want to do $SIG{ DIE } stuff, perhaps?

Replies are listed 'Best First'.
Re: Why 'die LIST'?
by suaveant (Parson) on Jul 24, 2001 at 20:52 UTC
    Maybe a more apt question is "Why not die LIST?"
    If it's easy to code, it still works as die "foo"; so why not make it easy on people and let them pass a whole list if they want?

    There may be a better reason, but this seems good enough to me... TIMTOWTDI

                    - Ant

(ichimunki) Re: Why 'die LIST'?
by ichimunki (Priest) on Jul 24, 2001 at 20:56 UTC
    Perhaps so that it works like a print statement.

    I could very easily see replacing all die()'s and warn()'s in production code with print LOG or something like that.
Re: Why 'die LIST'?
by Hofmator (Curate) on Jul 24, 2001 at 20:55 UTC

    maybe like the print function ... you could think of a 'die' as a 'print and do sth (i.e. die)'

    just my guess ...

    -- Hofmator

Re: Why 'die LIST'?
by doug (Pilgrim) on Jul 24, 2001 at 23:57 UTC
    It takes a list so the following works die "error with object ", $object->name(), " while processing bar(", $object->state(), ")\n"; I wish that the Carp family (croak, confess, etc) also took a list instead of .'ing everything. Ugly, ugly, ugly.
      Hmm, that would be a bug, then, since the documented behavior is "they act like die() or warn()...".

      Hmm, and it works for me:

      perl -MCarp -e "carp ('hello', 'world', qq(\n))";
      Looking at the code, it says, my $error = join '', @_; so it certainly is intending to work that way.

      —John

      They do. Look at the source of Carp.pm.

Re: Why 'die LIST'?
by rrwo (Friar) on Jul 27, 2001 at 06:22 UTC

    I've given die (and croak) list arguments. Why not?