In this post i will explain about aliases in array
In the program first we have defined one scalar variable and an array variable with same name, We printed the value of variable which is 100.After that we have called a subroutine with argument. In this subroutine the values of array will be printed.After that i have changed the value of scalar variable which will also change the value of global variable.
In the program first we have defined one scalar variable and an array variable with same name, We printed the value of variable which is 100.After that we have called a subroutine with argument. In this subroutine the values of array will be printed.After that i have changed the value of scalar variable which will also change the value of global variable.
#! /Perl/bin/perl
print("In this program we will see the effect of alias in array and scalar variable");
$var=100;
@var=(1,2,3,4);
print("\n\nThe value of \$var before subroutine call is $var\n");
&test_alias_sub(*var);
print("The value of \$var after subroutine call is $var\n");
sub test_alias_sub{
local(*array)=@_;
foreach $element(@array){
print("$element\n");
}
$array=200;
}
Output:print("In this program we will see the effect of alias in array and scalar variable");
$var=100;
@var=(1,2,3,4);
print("\n\nThe value of \$var before subroutine call is $var\n");
&test_alias_sub(*var);
print("The value of \$var after subroutine call is $var\n");
sub test_alias_sub{
local(*array)=@_;
foreach $element(@array){
print("$element\n");
}
$array=200;
}
0 comments:
Post a Comment