RE: From column to row?




It's definitely possible. The first thing to do is define your problem
a little better. Do you want four items per row, or do you want to
slurp the entire file and make one long comma-separated list?

This is a good starting project because it makes you learn how to open,
read, and write to files.

Here's a little snippet to get you started:



###############################
use strict;
use warnings;

open(INFILE,"<xy.txt") or die("Couldn't open 'xy.txt' for reading!\n");
open(OUTFILE,">xy.csv") or die("Couldn't open 'xy.csv' for writing!\n");

#reading and writing
while($_ = <INFILE>){
chomp $_;
#do something with $_...
print OUTFILE "This will be written to 'xy.csv'.\n";
}

###############################

Also check out:

perldoc -f open
perldoc -f print

You should be able to figure out how to rearrange it into the
appropriate format. If you have any trouble, post your code here and we
can help you.





-----Original Message-----
From: Andrej Kastrin [mailto:andrej.kastrin@xxxxxxxx]
Sent: Monday, November 28, 2005 11:45 AM
To: beginners@xxxxxxxx
Subject: From column to row?

Hi, I am totally NOOB in Perl and here is my first problem, which I
couldn't solve...
I have column data in file xy.txt, which looks like:
AAAAA
BBBBB
CCCCC
ABCDD
...
..

Now I have to transform this to row data file in the following way:
"AAAAA","BBBBB","CCCCC","ABCDD"

Is that possible?

Thanks in advance, Andrej


.