Re: How to pass the value of $@ to a subroutine
Thanks! Changing: my $message = @_; to: my ($message) = @_; did put the correct value in the string. If anyone cares to explain the difference between the code I had and the code Shishir suggested so I can understand why this makes a difference, I'm all ears! Thanks again, -Ian Shishir K. Singh wrote: Hello all, What I want to do is simple - if an error occurs on my previous command (in this case, making an FTP connection via Net::FTP), I want to send the value of $@ to a subroutine which sends an e-mail containing the value of $@ in the body. However, it is clear that I don't understand what $@ really is. Is it a string? A hash reference? When I simply print $@ after the failed command, I see the error I expect. But when I do something like: mailwarning($@) unless $ftp; and the subroutine mailwarning() has: my $message = @_; the value of $message is 1. Try my $message = shift; or my ($message) = @_; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to pass the value of $@ to a subroutine
Basically with the @_ and not having parens is like $var = scalar(@_); # which is one since @_ is to subs what @ARGV is to incoming Arguments passed to a module. So by doing the parens, you are populating the variables on the left with values being passed into the sub. Wags ;) ps others may be to make clearer. -Original Message- From: Ian Zapczynski [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 03, 2002 12:34 Cc: [EMAIL PROTECTED] Subject: Re: How to pass the value of $@ to a subroutine Thanks! Changing: my $message = @_; to: my ($message) = @_; did put the correct value in the string. If anyone cares to explain the difference between the code I had and the code Shishir suggested so I can understand why this makes a difference, I'm all ears! Thanks again, -Ian Shishir K. Singh wrote: Hello all, What I want to do is simple - if an error occurs on my previous command (in this case, making an FTP connection via Net::FTP), I want to send the value of $@ to a subroutine which sends an e-mail containing the value of $@ in the body. However, it is clear that I don't understand what $@ really is. Is it a string? A hash reference? When I simply print $@ after the failed command, I see the error I expect. But when I do something like: mailwarning($@) unless $ftp; and the subroutine mailwarning() has: my $message = @_; the value of $message is 1. Try my $message = shift; or my ($message) = @_; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to pass the value of $@ to a subroutine
Thanks! Changing: my $message = @_; to: my ($message) = @_; did put the correct value in the string. If anyone cares to explain the difference between the code I had and the code Shishir suggested so I can understand why this makes a difference, I'm all ears! @_ is an array. You were trying to do my $message = @_; Here $message will get the scalar value of the array i.e the number of elements in the array..which you are rightfully getting = 1. my ($message) = @_; ## This takes the value from @_ in array context and since there is only one element in @_, therefore, only one variable on the left side in array context is needed. Hence my ($message) = @_; you could have used my $message = shift; or my $message = $_[0]; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]