Friday, June 24, 2011

sending arrays as arguments in perl

Here we will learn how to send a array as argument in perl.
Here while sending data the reference of the array has to be sent .In the receiving end in the function we need to use special form of shift one of the below:

1)my @a = @{shift()};
2)my @b = @{shift()};
Simple shift can't be used here as it will shift only the scalar content;
Program:

sub myfunc
{
my @a = @{shift()};   # here @{+shift};  can also be used
print "@a";
}
package main;
@aa=("hello","aaaaa");
&myfunc (\@aa);  # take care here reference is used.

output:

hello aaaaa

No comments:

Post a Comment