Perl Subroutine help
Hi, I need to know how to pass parameter dynamically to perl subroutine
This is my program :-
#===========================================================#
#!/usr/bin/perl
@first = (1,2,3,4);
@second = (4,5,8,9);
@third = (1,2);
@forth = (5,9);
@firstArr = &fun2(@first,@second);
@secondArr = &fun2(@third,@forth);
print "printing newArray: @newArr\n";
print "printing secondArr: @secondArr\n";
sub fun2()
{
@new = @first; #need to pass this as dynamically to @new either @first or @third
@old = @second; #need to pass this as dynamically to @old either @two or @forth
$i = 0;
{
foreach $val1(@new){
foreach $val2(@old){
$res[$i] = $i;
# print "res : $res[$i]\n";
$i++;
}
}
}
return @res;
}
#===========================================================#
Sorry for my English.
Any help would be appreciated.
Thanks,
ABS
Last edited by abs_77; 05-05-2009 at 05:17 AM.
|