taint has asked for the wisdom of the Perl Monks concerning the following question:
I recently answered a simple post here. While I had no difficulty solving their riddle. I did find I had trouble getting Perl to better articulate any difficulties, should something go afoul.
While die (functions/die), and warn (functions/warn) get the job done to some degree. What if I'd like to help others with examples that provide more informative output from Perl? Sure use diagnostics can also be helpful. But to those new(ish) to Perl, the messages emitted can be somewhat cryptic. So I thought Carp might just be the answer, and started experimenting with it.
Perl says#!/usr/bin/perl -w # tester.cgi # dead simple script that hopefully won't work # as I want Perl to give me a nice informative # message, telling me why use strict; use Carp qw(cluck longmess shortmess); # example right out of perldoc my $long_message = longmess( "message from cluck() or confess()" ); # MYFILE does NOT exist my $file = "MYFILE"; # Perl, please inform me that the file MYFILE does not exist system ("cat $file" or $long_message());
OK that wasn't what I had hoped for. Let's adjust it a bit# ./tester.cgi syntax error at ./tester.cgi line 16, near "$long_message(" Execution of ./tester.cgi aborted due to compilation errors.
Perl (or system command) says#!/usr/bin/perl -w use strict; use Carp qw(cluck longmess shortmess); my $long_message = longmess( "message from cluck() or confess()" ); my $file = "MYFILE"; system ("cat $file" or confess(),cluck(),carp());
Hmm. I knew MYFILE didn't exist, and cat told me so.cat: MYFILE: No such file or directory
So is this the best way to get informative messages from Perl? This is a bit new to me, as I've always manufactured my error messages in the past 'cause I knew what the reason of failure (if any) would be.
Summary: how can I get the most informative, user friendly, error messages from Carp? Or is Carp even the best answer?
Thank you for all your consideration.
--Chris
Hey. I'm not completely useless. I can be used as a bad example.
|
|---|