Here's a fixed version, not much though into it, you can figure out how
to remove the trailing , 

$source_file = "input.txt";
$result_file = "output.txt";

open (SOURCE, $source_file) || die "cannot open $source_file: $!";
open (RESULT, ">$result_file") || die "cannot open $result_file: $!";

while (<SOURCE>)
{
   chomp; #Delete the NL character

   # If you don't want the quotation marks in your output remove the \"
from the next line
   print RESULT "\"$_\",";  # You opened the RESULTS file but did not
write to it...
}
close SOURCE; # Just make sure you close files after you are done with
them...
close RESULT;


+------------------------------------------
| José J. Cintrón
+------------------------------------------ 

> -----Original Message-----
> From: Andrej Kastrin [mailto:[EMAIL PROTECTED] 
> Sent: Monday, November 28, 2005 15:24
> To: Perl Beginners List
> Subject: Re: From column to row?
> 
> Chris Devers wrote:
> 
> >On Mon, 28 Nov 2005, Andrej Kastrin wrote:
> >
> >  
> >
> >>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?
> >>    
> >>
> >
> >Yes, it's possible.
> >
> >However, your description of the result you want doesn't 
> seem to match 
> >with the subject line you used -- I was expecting that you 
> want output 
> >like "ABCA", "ABCB..", "ABCD.", "ABCD", "ABCD". Which is it?
> >
> >Regardless, either way is possible.
> >
> >What have you tried so far?
> >
> >Anything?
> >
> >We can only help critique code you've attempted yourself.
> >
> >This is not a free script writing service.
> > 
> >
> >
> >  
> >
> I suppose that above example is not good one; here is the real one:
> Mark
> Francesco
> Ann
> Robert
> 
> transform to: "Mark","Francesco","Ann","Robert"
> 
> and here is my code:
> 
> $source_file = "input.txt";
> $result_file = "output.txt";
> 
> open (SOURCE, $source_file) || die "cannot open $source_file: 
> $!"; open (RESULT, ">$result_file") || die "cannot open 
> $result_file: $!";
> 
> while (<SOURCE>)
> {
> my($line) = $_;
> if ($line =~ $) #match to end of line
>    {
>       print "$line"; #how to make e.g. "Mark",
>    }
> }
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED] For 
> additional commands, e-mail: [EMAIL PROTECTED] 
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 

--
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