Dear All,

I would like a subroutine that will allow me to easily put columns of  a tab 
delimited file into their own arrays.

I've been calling the following repeatedly for each column:

my @array1 = getcolvals($filehandle, 0);
my @array2 = getcolvals($filehandle, 1);  ...etc.

sub getcolvals {
        @_ and not @_ % 2 or die "Incorrect number of arguments to 
getcolvals!\n";
        my $myfile = shift;
        my $mycol = shift;
        
        my @column = ();
        
        while (<$myfile>) {
                my ($field) = (split /\s/, $_)[$mycol]; 
                push @column, $field;     
        }

        return @column;
} 

This accomplishes exactly what I want, but it requires going through the whole 
file for each column extraction which seems inefficient.  Also, I want to know 
if I can modify the subroutine to return all the (arbitrary number of) columns 
at once into arrays. Any suggestions?

Many thanks,
Eric
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to