On Mon, Nov 28, 2005 at 08:45:14PM +0100 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"
> 
try this one:


#!/usr/bin/perl
# colrow1.pl

use strict;
use warnings;

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

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

$/ = undef;
my $file = <SOURCE>;

my %hash = split /\n/, $file;

foreach (sort keys %hash) {
print RESULT "$_ , $hash{$_}\n";
}
close SOURCE;
close RESULT;

hth
-- 
Gérard


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