Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2018-12-13 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many stories does it take before you've heard them all?







    Results (61 votes). Check out past polls.

    Notices?