## Functions and Arrays

Expand Messages
• Hello everyone!! I would like to know, and sorry if this is a stupid question, how can i pass two arrays into a function!!! I made one code that has two
Message 1 of 1 , Jun 2, 2003
Hello everyone!!

I would like to know, and sorry if this is a stupid question, how can
i pass two arrays into a function!!!

I made one code that has two functions that return an array each! And
them i have a third function that receives those two arrays.. but,
the problem is that the function joins the content of those two
arrays in the first array!!!

Example:

\$file1= "fich1.txt";
\$file2= "fich2.txt";

sub f1 { #receives one file and returns an array whith the
my(\$file)=@_; #content of that file
open(F1,\$file);
while (<F1>) {
chop;
\$f1[\$i]=\$_;
\$i++;
}
return @f1;
}

sub f2 { #the same thing
my(\$file)=@_;
open(F2,\$file2);
while (<F2>) {
chop;
\$f2[\$i]=\$_;
\$i++;
}
return @f2;
}

@f1=&f1(\$file1);
@f2=&f2(\$file2);
&ver(@f1,@f2); #calls the funstion and sends the two arrays

sub ver {

my (@array_1,@array_2)=@_;

print "exemplo de como pegar um item em especifico do array\n";

\$a=@array_1;
\$b=@array_2;
print "Tamanho do array 1: \$a\n";
print "Tamanho do array 1: \$b\n";

print "aa\$array_1[2]";

print " ==== ";

print "a\$array_2[1]";

print "\n \n \nImprime um array inteiro\n";

foreach \$x (@array_2)

{
print "\$x\n";

}
}

The problem is that in this last function the the first array gets
all the values!!! Why??

Thanks..

Nuno
Your message has been successfully submitted and would be delivered to recipients shortly.