in reply to RFC: "Best Practices" code review section
I use something like this:
package OpenOrDie; use strict; use warnings; use vars '@ISA @EXPORT $VERSION'; require Exporter; $VERSION = '0.30'; @ISA = 'Exporter'; @EXPORT = 'Open'; sub Open { my ($mode, $file) = @_; open my $fh, $mode, $file or die("Unable to open file '$file' using mode '$mode': $!") return $fh; }
Which I then use like:
use OpenOrDie; my $FILE = Open('<',$filename);
This also means I can catch the error consistently:
eval { my $FILE = Open('<',$filename); }; if ($@) { warn("Cannot parse configuration; $@"); $config{skip} = 1; }
<-radiant.matrix->
Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law
Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: RFC: "Best Practices" code review section
by merlyn (Sage) on Aug 15, 2005 at 20:21 UTC | |
by radiantmatrix (Parson) on Aug 16, 2005 at 15:16 UTC | |
by adrianh (Chancellor) on Aug 16, 2005 at 08:06 UTC |
In Section
Perl Monks Discussion