in reply to passing a value to a function
With this approach you would define two other accessor methods:sub cleararray { my $self = shift; for ( $i = 0; $self->radiovar(); $i++ ) { for ( $j = 0; $self->radiovar(); $j++ ) { @{$self->array()}[$i][$j] = undef; } } }
This way you aren't using error prone global variables, but you are writing better OO code.sub radiovar { my ( $self, $newval ) = @_; $self->{'radiovar'} = $newval if defined( $newval ); return $self->{'radiovar'}; } sub array { my ( $self, $newval ) = shift; $self->{'array'} = $newval if defined( $newval ); return $self->{'array'}; }
Now if your situation calls for only one $radiovar value per
class you could make it a class attribute pertaining to all object of Class X. Which would look something like:
package X; ... my $radiovar; ... sub radiovar { my $newval = shift; $radiovar = $newval if defined( $newval ); return $radiovar; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: passing a value to a function
by CharlesClarkson (Curate) on Jun 26, 2001 at 03:38 UTC |