you can use hash,where key is the column and value is the refrence to an array,and this array can contain multiple data.

--Hridyesh

Gunnar Hjalmarsson wrote:
Bobby wrote:
I have a text file with five colums of data (ColumA-E). Within each
column there could be multiple data with a comma seperating each piece of
data. How do i white a loop to parse through the data set and assign
each column a variable and each piece of data within that column a
different variable?

It sounds as if you should create a data structure rather than multiple scalar variables.

use Data::Dumper;
my @AoHoA;
<DATA>;
while (<DATA>) {
    chomp;
    my (%cols, %tmp);
    @cols{ qw/A B C D E/ } = split /\|/;
    foreach ( qw/A B C D E/ ) {
        push @{ $tmp{ "Column$_" } }, split /,/, $cols{$_};
    }
    push @AoHoA, \%tmp;
}
print Dumper [EMAIL PROTECTED];

__DATA__
ColumA|ColumB|ColumC|ColumD|ColumE
Test|A,F|ACY,FAC|ACYA,FCSA,FCSC|ACYEA,FCSA2
Test2|A|A1,A2,A3,A4,A5,A6|B1,B2|C1,C2,C3
Test3|B|b10,B11,B12,B13,|C1,C2|


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to