Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: subroutine array question

by Sidhekin (Priest)
on Aug 02, 2006 at 13:26 UTC ( #565220=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://565220]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2018-07-16 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (330 votes). Check out past polls.

    Notices?