Like the other monks have mentioned the parens after your function name are hurting you.
Another way of creating clearer OO code would be to encapsulate $radiovar an instance attribute of your class.
so you would have:
sub cleararray { my $self = shift; for ( $i = 0; $self->radiovar(); $i++ ) { for ( $j = 0; $self->radiovar(); $j++ ) { @{$self->array()}[$i][$j] = undef; } } }
With this approach you would define two other accessor methods:

so they might look something like this:
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'}; }
This way you aren't using error prone global variables, but you are writing better OO code.
Not to mention when using global variables inside your objects it kind of defeats the purpose of writing OO in the first place,
in that when a variable's purpose changes or you need to do something different to present that variable then you have to go
change lots more code than if you only had to change one or two subroutines. (That last statement may need some clarification.)

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; }

In reply to Re: passing a value to a function by linux454
in thread passing a value to a function by ralfthewise

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.