Erasmo Perez wrote:
> 
> I would like to thank you for all the support I have received from you
> in my last couple of questions.
> 
> But here is another question:
> 
> I would like to know how could I transform the following CSV file:
> 
> 1,2,3,4,5,6
> 2,3,4,6,7,8,9
> 3,876,986,876,765
> ...
> 987,983,654,990,654
> 989,876,234,56,67
> 
> into the following CSV file:
> 
> 1,2
> 1,3
> 1,4
> 1,5
> 1,6
> 2,3
> 2,4
> 2,6
> 2,7
> 2,8
> 2,9
> 3,876
> 3,986
> 3,876
> 3,765
> ...
> 987,983
> 987,654
> 987,990
> 987,654
> 989,876
> 989,234
> 989,56
> 989,67
> 
> I mean: the new CSV file must be composed of merely two columns, the
> first column needs to be the first value in the row of the input CSV.
> The second column must be the following numbers that follow the first
> number in the row, up to the end of the line
> 
> at the next line of the input CSV, again, the first number of the row
> must be attached to the remaning numbers in its row, a la
> 
> a,b,c,d
> f,g,h,i,j
> 
> to be converted in
> 
> a,b
> a,c
> a,d
> f,g
> f,h
> f,i
> f,j
> 
> How could I accomplish this using Perl ?

while (<DATA>) {
  chomp;
  my ($first, @data) = split /,/;
  print "$first,$_\n" foreach @data;
}


HTH,

Rob

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


Reply via email to