It'd be helpful if you showed any error messages or explained what you got vs what you expected to get.

You seem to be using the parameters to circ_area as rvalues when you modify each parameter in turn. This will modify the original values as passed in, except that those values are constants and not modifyable. Then you return them - so that's just confusing. Why modify in place, and then return new copies?

Also, you don't need the &. So get rid of it.

Option 1:

my @area = (5,6,7); circ_area(@area); # rest as-is
Of course, this makes your code a liar - the area of those circles aren't 5, 6, and 7. The values are misleading until after the call to circ_area.

Option 2:

# rest as-is sub circ_area { map { 3.14 * ($_ ** 2) } @_; }
Here we are creating a new array by mapping from the input values to some new output values. Since we don't assign back to $_, we aren't overwriting the constant inputs. This would be the way I suggest going.


In reply to Re: subroutine array question by Tanktalus
in thread subroutine array question by Anonymous Monk

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.