in reply to subroutine arguments

Try passing the list as a reference, for example:
cog_class(\@c1_uniq_cog_ids, $name1);
Then, shift off the list within the function, like so:
my $c1_uniq_cog_ids = shift; my $name = shift;
So you finish up with something like:
#!/usr/bin/perl -w use strict; my $name1="chrom1 unique"; my @c1_uniq_cog_ids = qw(1 2 3 4 5); print "NAME1 $name1\n"; cog_class(\@c1_uniq_cog_ids, $name1); sub cog_class { my $c1_uniq_cog_ids = shift; my $name = shift; print "NAME $name\n"; for my $id ( @{$cog_ids_ref} ){ # BLAH BLAH } }
Update:
Oh, one more thing... that C-style for loop that you have is probably better written either as:
foreach my $id (@{c1_uniq_cog_ids}) { # Do stuff }

or even....
for (@{c1_uniq_cog_ids}) { # Do stuff }
Update 2: Fixed, as pointed out by [id://cbrandtbuffalo]
hope this helps

--Darren

Replies are listed 'Best First'.
Re^2: subroutine arguments
by cbrandtbuffalo (Deacon) on Oct 25, 2005 at 12:22 UTC
    I'm not sure your example will completely work as shown. The first shift in your sub will pull off a reference to the array, not the array itself. So the sub should look something like:
    sub cog_class { my $cog_ids_ref = shift; my $name = shift; print "NAME $name\n"; for my $id ( @{$cog_ids_ref} ){ # BLAH BLAH } }
Re^2: subroutine arguments
by revdiablo (Prior) on Oct 25, 2005 at 14:11 UTC
    Try passing the list as a reference ... Then, shift off the list

    I don't mean to sound petty, but in situations like this it's especially important to be mindful of the difference between an array and a list. You can't take a reference to a list. It's an array reference.