Lotus1 has asked for the wisdom of the Perl Monks concerning the following question:
While updating an old program I noticed I had passed a list from die() to a scalar parameter in a subroutine. Even though the list only contained one element I assumed this was a bad practice. Out of curiosity I tested adding a second element and was surprised that the next parameter didn't get overwritten because the @_ elements were squashed into a single string. This seems useful but is it safe to rely on something like this?
use strict; use warnings; my @msg = ( "This is line one.", "Line two.\n" ); die @msg; sub BEGIN { $SIG{__DIE__} = sub { my @log_files = qw( error.log ftp.log ); send_status_email( 'me@work.com', 'script error', @_, \@log_fi +les ); }; } sub send_status_email { my ($to_address, $status, $message, $ar_attachments ) = @_; print "To: $to_address\n"; print "Status: $status\n"; print "Message <$message>\n"; foreach ( @$ar_attachments ) { print "ar: $_\n"; } print "***************** sub finished\n"; } __END__ **Output** To: me@work.com Status: script error Message <This is line one.Line two. > ar: error.log ar: ftp.log ***************** sub finished This is line one.Line two.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why are list items passed to die() combined into a string?
by kennethk (Abbot) on Jan 13, 2015 at 17:13 UTC | |
by Lotus1 (Vicar) on Jan 13, 2015 at 18:52 UTC | |
by kennethk (Abbot) on Jan 13, 2015 at 19:25 UTC | |
by Lotus1 (Vicar) on Jan 13, 2015 at 22:31 UTC | |
|
Re: Why are list items passed to die() combined into a string?
by roboticus (Chancellor) on Jan 13, 2015 at 17:01 UTC | |
by Lotus1 (Vicar) on Jan 13, 2015 at 18:40 UTC | |
by Mr. Muskrat (Canon) on Jan 29, 2015 at 22:23 UTC | |
|
Re: Why are list items passed to die() combined into a string?
by locked_user sundialsvc4 (Abbot) on Jan 13, 2015 at 18:11 UTC |