CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
sending array as a function argument

 



zeppelin girl
New User

Nov 4, 2008, 10:59 PM

Post #1 of 2 (419 views)
sending array as a function argument Can't Post

Hi .
i'm trying to run the following code:

sub main {
my @array;
....
while (my $next=<IN>) {
my @split=split("\t",$next);
if (@split[0] eq $ARGV[0]) {
@array=@split[1..39];
last;
}
}
....
return pearson_correlation(@array);
} #end of main


sub pearson_correlation {

my @geneArr=@_;
foreach (@geneArr) {
print "current : $_\n";
}
......
}

and something is wrong here: i get the output:

current : 1 0 1.71 1.51 0 1.77 1.43 0 0 1.43 0 2.23 1.68 3.27 0 3.46 2.61 1.94 2.83 0 3.03 3.49 2.28 1.60 0 0 0 1.51 0 0 4.49 2.82 2.37 1.20 2.37 0 0 3.89

current :
current :
current :
current :
current :
current :
current :
current :
current :
current :
current :
current :
.... (38 times)

i've tried to send the array by reference but it doesn't work as well.
i'm trying to split the first "current" by tab- doesn't work.
how can i get the array properly?


FishMonger
Veteran / Moderator

Nov 5, 2008, 4:09 AM

Post #2 of 2 (407 views)
Re: [zeppelin girl] sending array as a function argument [In reply to] Can't Post

The values are most likely not separated by a tab, they are probably separated by 1 or more spaces. Also, the first arg to split is a pattern not a string, so use a regex.

my @split = split(/\s+/, $next);


@split[0] is better written as $split[0] since it's a single array element, not an array slice.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives