Passing scalar variable to a subroutine by reference using $_ : Scalar Reference « Language Basics « Perl






Passing scalar variable to a subroutine by reference using $_

    

#!/usr/bin/perl -w

use strict;

my $var = 10;
print "before: $var\n";
change_var($var);
print "after:  $var\n";

sub change_var {
    print "in change_var() before: $_[0]\n";
    ++$_[0];
    print "in change_var() after:  $_[0]\n";
}

   
    
    
    
  








Related examples in the same category

1.Get reference to a scalar
2.Scalar alias
3.Using scalar reference
4.The backslash operator means "adddress of"