volks,

I'm playing around with a little perl module and I came
across to different solutions - thought I would ask for
opinions as to which would be more Kosher - so why not
ask folks who might have an opinion:

Plan A: The simple 'undef' trick

        #------------------------
        sub get_Lock {
         my ($self, $name) = @_;
        (exists $self->{$name}) ? $self->{$name}->{var_lock} : undef;
        } # end of get_Lock

Plan B: your basic Croak Play

        #------------------------
        sub get_Lock {
                my ($self, $name) = @_;
                croak "No such variable $name \n"
                        unless (exists $self->{$name}) ;
                $self->{$name}->{var_lock};
        } # end of get_Lock

Under Plan A - one would code it like:
        
        my $lock = $global->get_Lock('var1');

        BailOut("bad var1\n") unless ( defined( $lock ) ) ;

since, well - it is possible that 'var1' does not exist...

Under Plan B - one gets the SCREAM from croak right off

        [jeeves:pbl/bloopers/dumbDrieux] drieux% perl OO_GlobalGame.txt
        No such variable var1
         at OO_GlobalGame.txt line 14
        [jeeves:pbl/bloopers/dumbDrieux] drieux%

and one could go look at line 14 of their code and go....
"Oh dear, never really meant that one - meant to check 'var'
or what ever it should have been....

Opinions?


ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to