Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > References and subroutines

Reply
Thread Tools

References and subroutines

 
 
ReaprZero
Guest
Posts: n/a
 
      12-04-2003
Hello,

I'm a C programmer who recently came to Perl so this is a little
confusing.

If I have a local variable, how do I pass it to a subroutine as a
reference (like a C pointer) and have the subroutine be able to modify
the contents of the variable? I've looked into references but all I
can find is stuff on passing array and hash references.

Thanks,
Alex
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-04-2003
ReaprZero wrote:
> If I have a local variable, how do I pass it to a subroutine as a
> reference (like a C pointer) and have the subroutine be able to
> modify the contents of the variable?



my $var = 1;

increment(\$var);

sub increment {
my $ref = shift;
$$ref += 1;
}

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File handling with subroutines and references Eric Martin Perl Misc 16 01-19-2006 04:00 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
how to understand references to variables and references to constants are distinguished? baumann.Pan@gmail.com C++ 3 11-10-2004 04:16 AM
References Subroutines and Arrays Ketema Perl Misc 2 03-06-2004 01:49 PM
Pointers and References (and References to Pointers) Roger Leigh C++ 8 11-17-2003 10:14 AM



Advertisments