Hiya,
sounds like a prime example of a hash of arrays. You would have a hash
for record types - 'c1' 'c2' etc., with each hash element being a
reference to an array. The code below is not very good, but should
give you an idea
__BEGIN__
#!/usr/bin/perl -w
use strict;
my %cols=();
my $maxlen=0;
open(f1,"t1")||die "can't open t1: $!\n";
while(<f1>) {
my ($type,$rec)=split;
print "type=$type rec=$rec\n";
$maxlen=length $rec if length $rec > $maxlen; # get col width
push @{$cols{$type}},$rec; # add rec to correct column
}
close(f1);
my $line='';
$maxlen++; # space columns
my $spacer=' ' x $maxlen;
foreach (sort keys %cols) {
$line.=substr($_.$spacer,0,$maxlen) ; # pad string
}
print "$line\n";
my $i=0;
while (1) {
$line="";
foreach (sort keys %cols) {
$line.=(defined $cols{$_}[$i]) ?
substr($cols{$_}[$i].$spacer,0,$maxlen) :
$spacer;
}
$line=~s/ +$//; # remove trailing spaces
last if $line eq ''; # exit if no details left
print "$line\n";
$i++;
}
__END__
On Wednesday 06 June 2001 10:15 am, Diego Riaņo wrote:
> Hi everybody
>
> I am working on some kind of files and i have to change the format
> and get a table.
>
> thes files had the following form:
>
> c1 kdlsakdlksa
> c2 djskadklsa
> c2 djksadlsadaskdj
> c3 dskadjlkj
> c4 dksadkasdljsa
>
> I will to chenge them to this:
>
> c1 c2 c3
> c4 kdlsakdlksa djskadklsa dskadjlkj
> dksadkasdljsa djksadlsadaskdj
>
> Could someone help me?
>
> thanks in advances
>
> DiegoM
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000