subr01 has asked for the wisdom of the Perl Monks concerning the following question:
How to pass a filename or a filehandle, two arrays to a function? I have done this:
open INPUT,"$old"; my (@arrayold,@arraynew); myfunc(*INPUT,\@arrayold,\@arraynew) sub myfunc { my ($file,@array1,@array2) = @_ ; my $j = 0; my $k = 0; while (my $line = <$file) { my($word1,$word2) = split(",",$line); $array[$j++] = $word1; $array[$k++] = $word2; } }
As you can guess, my function reads a file which has info like:
1,//http:abcd 2,//http:avcd
into two arrays one containing the number and the other containing the address. I am only getting blank arrays. Am I passing it wrong? Kindly help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing a file handle and two arrays to a function by reference.
by toolic (Bishop) on May 26, 2015 at 13:34 UTC | |
|
Re: Passing a file handle and two arrays to a function by reference.
by Athanasius (Archbishop) on May 26, 2015 at 13:46 UTC | |
|
Re: Passing a file handle and two arrays to a function by reference.
by neilwatson (Priest) on May 26, 2015 at 13:32 UTC | |
by Anonymous Monk on May 26, 2015 at 13:37 UTC | |
|
Re: Passing a file handle and two arrays to a function by reference.
by neilwatson (Priest) on May 26, 2015 at 13:58 UTC | |
|
Re: Passing a file handle and two arrays to a function by reference.
by BillKSmith (Monsignor) on May 26, 2015 at 17:43 UTC |