Ok, here goes nothing, my first post as an answer to someone. I hope I get this right...
It was said before that you don't need to declare the function with the parens. So:

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


In reply to Re: passing a value to a function by derek3000
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.