By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,955 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,955 IT Pros & Developers. It's quick & easy.

Printing errors to browser

Kelicula
Expert 100+
P: 176
Does anyone know of a way that I can have the errors on a cgi script be funneled to the http output?

I have use warnings, and the

Expand|Select|Wrap|Line Numbers
  1. or die "can't open it $!\n";
But still to this day I have never seen what is in $!. Or recieved a warning.

All I ever get is Internal server error, or it works.

Another thing that is very weird, I was working on this set transparant color, with the GD module, and it worked fine. Here is the script:

Expand|Select|Wrap|Line Numbers
  1. #!user/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use GD;
  6.  
  7. my $image = GD::Image->newFromJpeg("../img/logoTest.jpg");
  8. my $black = $image->colorResolve(0,0,0);
  9. $image->transparent($black);
  10. $image->interlaced('true');
  11. my ($width,$height) = $image->getBounds();
  12. my $count = 0;
  13. for (my $x = 0; $x < $width; $x++) {
  14.      for (my $y = 0; $y < $height; $y++) {
  15.          my $color = $image->getPixel($x,$y);
  16.          my ($r,$g,$b) = $image->rgb($color);
  17.          if ($r < 30 && $g < 30 && $b < 30) {
  18.              $image->setPixel($x,$y,$black);
  19.              $count++;
  20.          }
  21.      }
  22.  }
  23. print "$count\n";
  24. open(FILE, ">../img/background2.png") || die "Cannot open background2.jpg: $!\n";
  25. print FILE $image->png;
  26.  
However I noticed that I had grabbed the wrong jpg to set transparency for, so I changed it
Expand|Select|Wrap|Line Numbers
  1. my $image = GD::Image->newFromJpeg("../img/otherOne.jpg");
And now it doesn't work. Internal error.

I have looked through it for hours now, and can't see what I messed up. I litarally just changed four or five characters.

I'd love to get the errors to the screen
Thanks!!

PS -
I tried running it on my local machine, but it says GD is not found. Can't open GD/Image found in C:/perl/bin/lib (or whatever the path was I'm not looking at the error now)
Sep 9 '07 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Does anyone know of a way that I can have the errors on a cgi script be funneled to the http output?

I have use warnings, and the

Expand|Select|Wrap|Line Numbers
  1. or die "can't open it $!\n";
But still to this day I have never seen what is in $!. Or recieved a warning.

All I ever get is Internal server error, or it works.

Another thing that is very weird, I was working on this set transparant color, with the GD module, and it worked fine. Here is the script:

Expand|Select|Wrap|Line Numbers
  1. #!user/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use GD;
  6.  
  7. my $image = GD::Image->newFromJpeg("../img/logoTest.jpg");
  8. my $black = $image->colorResolve(0,0,0);
  9. $image->transparent($black);
  10. $image->interlaced('true');
  11. my ($width,$height) = $image->getBounds();
  12. my $count = 0;
  13. for (my $x = 0; $x < $width; $x++) {
  14.      for (my $y = 0; $y < $height; $y++) {
  15.          my $color = $image->getPixel($x,$y);
  16.          my ($r,$g,$b) = $image->rgb($color);
  17.          if ($r < 30 && $g < 30 && $b < 30) {
  18.              $image->setPixel($x,$y,$black);
  19.              $count++;
  20.          }
  21.      }
  22.  }
  23. print "$count\n";
  24. open(FILE, ">../img/background2.png") || die "Cannot open background2.jpg: $!\n";
  25. print FILE $image->png;
  26.  
However I noticed that I had grabbed the wrong jpg to set transparency for, so I changed it
Expand|Select|Wrap|Line Numbers
  1. my $image = GD::Image->newFromJpeg("../img/otherOne.jpg");
And now it doesn't work. Internal error.

I have looked through it for hours now, and can't see what I messed up. I litarally just changed four or five characters.

I'd love to get the errors to the screen
Thanks!!

PS -
I tried running it on my local machine, but it says GD is not found. Can't open GD/Image found in C:/perl/bin/lib (or whatever the path was I'm not looking at the error now)
One of our resident experts (KevinADC), has written a tutorial on CGI under the Articles section of this site. In there, under the Modules section, you will find the following:

Expand|Select|Wrap|Line Numbers
  1. use CGI::Carp qw/fatalsToBrowser/;
  2.  
along with an explanation. I recommend the tutorial as it is an excellent beginning. (as far as I have seen as I am still reading it)

Regards,

Jeff
Sep 9 '07 #2

KevinADC
Expert 2.5K+
P: 4,059
To expand on that, you can aso print warnings. see the "MAKING WARNINGS APPEAR AS HTML COMMENTS" in the CGI::Carp documentation.
Sep 9 '07 #3

KevinADC
Expert 2.5K+
P: 4,059
There is a new module that looks interesting:

CGI::Carp::DebugScreen
Sep 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.