Re: From column to row?



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

.



Relevant Pages

  • Re: Help With Sorting
    ... Need help sorting the column data ... The problem I run into is that I need to sort by the ... Dave Peterson ... Prev by Date: ...
    (microsoft.public.excel)
  • RE: Multiple conditions
    ... if your H column data starts at say row 10 ... in M10 enter ... in M11 enter ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • Calculating frequency?
    ... I am trying determine how many times a number occurs a five column data ... sheet. ... Lost in formuland- ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • Column Data into a Pie Chart?
    ... I've got an Excel sheet composed of column data. ... I want to put a pie chart on another ... Apples ... Prev by Date: ...
    (microsoft.public.excel.misc)