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

Hi, Im using a webapp created with CGI::App, I want to email the oracle errors to our support team. I send emails with Mime::lite, this works fine. My emailerror sub is:
emailerror{ my $error = @_; warn "error: $error"; return; } if I call this with any other value from my app it works fine, when I call itpassing $self->dbh->errstr then it doesnt work
  • Comment on CGI::App catch and email database errors

Replies are listed 'Best First'.
Re: CGI::App catch and email database errors
by choroba (Cardinal) on Apr 12, 2010 at 10:46 UTC
    You are assigning an array to a scalar, which means the $error variable is going to contain the number of arguments to the sub, which is probably not what you intended.
      Also using warn as a way to send email is doubly weird
        it is only an example, to prove that I'm not geting passed what I thought. As you can see from the example sub, there is no email sent.
      HOw do I do this properly then?

        You could try:

        my ($error, $next_arg)=@_; # Grab multiple items at once my $error2 = $_[0]; # Access the item you want my $error3 = shift; # Shift it off the argument list

        ...roboticus

        perlintro
        foo(1,2,3,9); sub foo { my $scalar = @_; my( $one, $two, $three, $four ) = @_; warn $scalar; warn "$one $two $three $four "; } __END__ 4 at - line 6. 1 2 3 9 at - line 7.
Re: CGI::App catch and email database errors
by Anonymous Monk on Apr 12, 2010 at 09:29 UTC
    then it doesnt work

    It is not likely it ever worked.