Thanks, Chris and Wiggins!

- Bryan



> On Fri, 16 Dec 2005, Bryan R Harris wrote:
> 
>> I remember from my C++ class that when you pass arguments to
>> subroutines you can pass them either as a pointer to the real variable
>> (so you modify the original if you change it), or as a copy (which you
>> can change all you want and not affect the original).
> 
> The terminology I was taught for this was "pass by reference" to denote
> sending around pointers to the same physical memory location, and "pass
> by value" to denote sending around abstract logical pieces of
> information that are typically copies of the original variable.
> 
> Like most languages, Perl has ways to do both of these.
> 
> Normal argument passing in Perl is basically like pass by value or pass
> by copy. You don't generally have to do anything extra to get this
> behavior.
> 
> To pass a reference to a variable to a subroutine, prefix the variable
> name with a backslash: \%myhash, [EMAIL PROTECTED], etc. You can capture this
> reference into a scalar -- $hashref = \%myhash -- and then access the
> contents of the reference by dereferencing: $$hashref{"KEY"} = "VALUE";
> 
> This is explained in detail in perldoc's perlref and perlobj pages:
> 
> http://perldoc.perl.org/perlref.html
> http://perldoc.perl.org/perlobj.html
> 
> It's also in books like _Learning Perl Objects, References & Modules_
> and _Object Oriented Perl_:
> 
> http://www.oreilly.com/catalog/lrnperlorm/
> http://www.amazon.com/exec/obidos/tg/detail/-/0596004788?v=glance
> http://books.perl.org/book/200
> 
> http://www.manning.com/Conway/
> http://www.amazon.com/exec/obidos/tg/detail/-/1884777791?v=glance
> http://books.perl.org/book/171
> 
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to