Please see the sample code below:
While func1 calls func3 & func4, the private variables $v1 & $v2 in func1 are implicitly passed into func3, but not into func4. Apparently, the parenthesis in red makes a significant difference.
While func2 calls func5 & func6, the private variable $v1 & $v2 in func2 can not be implicitly passed into either func5 or func6.
Could someone please explain to me why there are such differences? I cannot see any advantages of this implicitly passing. Nor do I understand why $v1 & $v2 in func2 can not be implicitly passed into func5.
Below is the output of a test run:
Code:
#! /usr/bin/perl
use strict;
use warnings;
my $var = "a";
&func1($var, 'b');
&func2;
exit;
sub func1 {
my ($v1, $v2) = @_;
&func3;
&func4[b][COLOR=red]()[/color][/b]; # the parenthesis makes a difference!!
}
sub func2 {
my $v1 = "a";
my $v2 = 'b';
&func5;
&func6();
}
sub func3 {
my ($v1, $v2) = @_;
print "In func3. \$v1 = $v1, \$v2 = $v2\n";
}
sub func4 {
my ($v1, $v2) = @_;
print "In func4. \$v1 = $v1, \$v2 = $v2\n"; # line 31
}
sub func5 {
my ($v1, $v2) = @_;
print "In func5. \$v1 = $v1, \$v2 = $v2\n"; # line 36
}
sub func6 {
my ($v1, $v2) = @_;
print "In func6. \$v1 = $v1, \$v2 = $v2\n"; # line 41
}
While func1 calls func3 & func4, the private variables $v1 & $v2 in func1 are implicitly passed into func3, but not into func4. Apparently, the parenthesis in red makes a significant difference.
While func2 calls func5 & func6, the private variable $v1 & $v2 in func2 can not be implicitly passed into either func5 or func6.
Could someone please explain to me why there are such differences? I cannot see any advantages of this implicitly passing. Nor do I understand why $v1 & $v2 in func2 can not be implicitly passed into func5.
Below is the output of a test run:
Code:
% tt.pl
In func3. $v1 = a, $v2 = b
Use of uninitialized value in concatenation (.) or string at ./callSub2.pl line 31.
Use of uninitialized value in concatenation (.) or string at ./callSub2.pl line 31.
In func4. $v1 = , $v2 =
Use of uninitialized value in concatenation (.) or string at ./callSub2.pl line 36.
Use of uninitialized value in concatenation (.) or string at ./callSub2.pl line 36.
In func5. $v1 = , $v2 =
Use of uninitialized value in concatenation (.) or string at ./callSub2.pl line 41.
Use of uninitialized value in concatenation (.) or string at ./callSub2.pl line 41.
In func6. $v1 = , $v2 =