Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://565220]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-09-26 08:40 GMT
Find Nodes?
    Voting Booth?
    Eventually, "covfefe" will come to mean:

    Results (205 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!