How about something like this?  I'm returning just the second element of the 
resulting list of using split() on $_.
 
This shortcut for getting just one element of a list can be used on any 
function that returns a list.  Naturally this is not the most efficient method, 
so your mileage may vary.
 
################
 
use strict;
use warnings;
 
my @columnTwo;
open(INFILE,"<","myfile.txt") or die("Couldn't open 'myfile.txt' for 
reading!\n");
 
while(<INFILE>){
    push @columnTwo,(split(/\s+/,$_))[1];
}
 
#################

        -----Original Message----- 
        From: Andrej Kastrin [mailto:[EMAIL PROTECTED] 
        Sent: Tue 12/27/2005 1:41 AM 
        To: beginners@perl.org 
        Cc: 
        Subject: read column into array
        
        

        Hi all,
        
        is there any simple way to read a column of a file into array; e.g. read
        second column
        a b h
        e r z
        u e u
        
        and write it to @array=(b,r,e).
        
        Cheers, Andrej
        
        
        --
        To unsubscribe, e-mail: [EMAIL PROTECTED]
        For additional commands, e-mail: [EMAIL PROTECTED]
        <http://learn.perl.org/> <http://learn.perl.org/first-response>
        
        
        

Reply via email to