http://qs321.pair.com?node_id=974377

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

I am writing an object. Upon initialization of the object, if there is a problem for whatever reason (loading data or anything) I want to return null and put an error in $!. Here is my object:

package coolobject; use strict; our @ISA = qw/Exporter/; our @EXPORTER = qw/new/; sub new{ my $class = shift; my $self; $self->{name} = 'new'; bless ($self); if ($self->loaddata()){ return $self; }else{ $! = "Error loading data!"; undef $self; return undef; } } sub loaddata{ my $self = shift; return undef; }

and here is where I am using the object

my $obj = coolobject->new or die "$!";

When I run it though, I don't get any value in $!. How am I supposed to do this?