CoderZone.org

Category: >> Perl Code >> Call subroutine and pass variable by value Bookmark and Share

<< lastnext >>

Snippet Name: Call subroutine and pass variable by value

Description: Call a subroutine and pass a variable by value.

Comment: (none)

Author: CoderZone
Language: PERL
Highlight Mode: PERL
Last Modified: March 06th, 2009

$value = "foo";
$newvalue = add_bar($value);
print "$value becomes $newvalue";
 
sub add_bar {
    my ($copy) = @_;
    $copy .= "bar";
    return $copy;
}
 
# foo becomes foobar
 
# the special @_ array will always contain aliases to the 
# variables that are passed in, so it really isn't possible 
# to pass by value.
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 7