Re: From column to row?
- From: jag.robin18@xxxxxxxxxx (Gerard Robin)
- Date: Tue, 29 Nov 2005 01:28:30 +0100
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
.
- References:
- From column to row?
- From: Andrej Kastrin
- From column to row?
- Prev by Date: RE: From column to row?
- Next by Date: Re: From column to row?
- Previous by thread: Re: From column to row?
- Next by thread: RE: From column to row?
- Index(es):
Relevant Pages
|
|