LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-06-2005, 11:13 AM   #1
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 31
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?
 
Old 02-06-2005, 01:00 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.
 
Old 02-06-2005, 09:02 PM   #3
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Original Poster
Rep: Reputation: 31
Darn. Sorry Paul. My initial question was faulty. I meant with *built-in* functions. Any further insight is appreciated.
 
Old 02-06-2005, 10:22 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return variables in scripts Elec490 Programming 8 08-22-2005 09:10 AM
return statement in functions pantera Programming 2 12-06-2004 06:21 PM
How to use return values from system functions? kpachopoulos Programming 2 07-30-2004 03:09 AM
Is it possible to return variables from a script? pedrosan Linux - Newbie 6 04-20-2004 05:51 AM
fork and copies of variables Griffon26 Programming 3 08-23-2002 07:45 AM


All times are GMT -5. The time now is 11:23 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration