Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Any last words?

by broquaint (Abbot)
on Nov 22, 2001 at 16:50 UTC ( #126960=perlmeditation: print w/ replies, xml ) Need Help??

Playing about with signal handlers the other day, I came across a rather unusual caveat - when you pass multiple arguments to die() or warn() they are concatenated together, whether they are strings or not, and put into the first parameter of the handlers.
use strict; $SIG{'__DIE__'} = sub { local $" = ', '; # this will have no effect on @errs my @errs = @_; print "$0: @errs"; exit(1); }; die('foo', {'bar' => 'xxx'}, ['baz','quux']); __END__ output - fooHASH(0x80f9964)ARRAY(0x810a014) at line 9.
This is counter-intuitive since one expects to pass a LIST and get the same at the other end. While I am aware that signal handlers traditionally only take a single argument, this particular caveat is not explained in the docs (although it alludes to taking a single argument, as the example code always used $_[0] when referring to the arguments). Also, I'm fairly sure this is consistent across all platforms since the concatenation is hard-coded in the perl source (i.e no platform dependent #ifdef's).

So this is not so much a bug (as I first thought it might be) as an inconsistency between the documentation and the code. Perhaps some wisened monks out there could enlighten me as to the purpose of this 'feature' ...


Comment on Any last words?
Download Code
Replies are listed 'Best First'.
Re: Any last words?
by Anonymous Monk on Nov 23, 2001 at 02:22 UTC
    No man, this is plain parameter passing rules in action. You are passing references.

    This will do:

    my %hash= qq(bar xxx);

    my @array = qq(baz quux);

    die('foo ',%hash, @array);


Re: Any last words?
by pike (Monk) on Nov 23, 2001 at 15:03 UTC
    'die' concatenates its argument like print does. This is so that you can say e.g.

    die "Expected ", scalar (@ref), " arguments, got ", scalar (@arr), "\n +";

    rather than having to explicitly concatenate the strings:

    die "Expected " . scalar (@ref) . " arguments, got " . scalar (@arr) . + "\n";

    The downside to this is that the args are obviously also concatenated when you pass the to a handler.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://126960]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2015-12-02 03:51 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (33 votes), past polls