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.
In reply to Why are list items passed to die() combined into a string? by Lotus1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |