perlquestion
SomeNetworkGuy
<p>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:</p>
<code>
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;
}
</code>
<p> and here is where I am using the object </p>
<code>
my $obj = coolobject->new or die "$!";
</code>
<p>When I run it though, I don't get any value in $!. How am I supposed to do this?</p>