http://www.perlmonks.org?node_id=565220


in reply to subroutine array question

what am I doing wrong here

You are trying to modify 5, 6, and 7. It's a good thing Perl does not let you, or math would be a tricky thing to do.

You might want to make some copies, somewhere or other. Since your function is returning values, you probably don't want it to also change the input values, and so I would choose to make the copies there:

my @area = &circ_area(5,6,7); foreach (@area) { print $_ . "\n"; } sub circ_area { my @x = @_; # the copy is writable! foreach (@x) { $_= 3.14 * ($_**2); # so this works! } return (@x) }

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!