Do Perl functions usually modify variables, or return modified copies? Why?
Do Perl functions usually modify variables, or return modified copies?
I know I can just try out various functions and find out for myself, but what's the rationale for whichever is more perlish? |
SHORT ANSWER:
Perl passes references to its parameters (rather than make copies of them). So if a parameter is modified in a Perl subroutine, then that value will also be modified in the caller. LONGER ANSWER: There are many different ways to declare and invoke Perl subroutines, and many ways to handle Perl subroutine parameters. You can, for example, do recursion (which requires "pass by value" semantics) in Perl. |
Darn. Sorry Paul. My initial question was faulty. I meant with *built-in* functions. Any further insight is appreciated. :)
|
It depends ;)
eg sin(expr) rtns the sin of the value supplied, otoh ''pop': Pops and returns the last value of the array, shortening the array by one element'. See http://search.cpan.org/~nwclark/perl...Perl_Functions for a definitive list. Enjoy :) |
All times are GMT -5. The time now is 06:34 PM. |