Need a little help with die function.

They have: 62 posts

Joined: May 2000

OK, I have this example. The following file, needless to say, doesn't exist. If I try to open it, the die should print "No file: " and the STDERR, right? Well, when I try it out, I just get a blank document with none of the text.

open(HEH, "<nofile.html") || die "No file: $!\n";
@blank=<HEH>;
close(HEH);
'

So, what's my problem?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Which reminds me of the dated "what's your damage?", lol...

open (HEH, "nofile.html") or die "\n\n\n Oh no! We are missing the most important file! nofile.html! \n\n\n";

I am a little melodramatic in my coding, yes.

Perhaps it can't find "

They have: 62 posts

Joined: May 2000

Well, I tried it without the "<" to still no avail. *sigh*

They have: 161 posts

Joined: Dec 1999

The die() and warn() functions print their messages to STDERR, not STDOUT. And in a CGI program, STDERR is connected to the server's error log, and STDOUT is connected to the browser.

Use the CGI::Carp module:

use CGI::Carp 'fatalsToBrowser';
# guess what that does...

die "oh no, Mr. Bill!";
# that gets sent to the error log AND the browser
'

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.