in reply to passing a value to a function
sub cleararray{ #code }
will do fine.
So as it stands, even if you did call it like:
cleararry($radiovar);
it still won't work, because the variable that you're popping off the argument list goes to $class, which is not what you want, because you wouldn't do anything with it. Also, the way it is now, you're just using a global variable ($radioval), so passing it isn't necessary. I am not saying that this is good!! I haven't done too much OO myself, but I think I would do it like this, but keep in mind, TMTOWTDI:
sub clear_array{ my($self, $var) = @_; my @array; for(my $i = 0; $i < $var; $i++){ for(my $j = 0; $j < $var; $j++){ $array[$i][$j] = 0; } } return @array; }
I'm sure there's an easier way to do it. There's probably a function that will do this for you already. My version keeps all variables local to the function, which is usually a good practice (I think). But anyway, since it's like this, it returns a two-dimensional array with all of its values set to 0. So to call it:
my $leroy = patterns->new(); #or my $leroy = new patterns; @array_to_be_cleaned = $leroy->clear_array($radioval);
If there really isn't any special reason that you're passing in $radioval, then you could just use foreach, I think. I hope this helps, and that I didn't mess up and confuse you more.
happy coding,
Derek
|
---|