-----Original Message-----
From: Diego Ria�o <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: June 06, 2001 9:15 PM
Subject: Tables help


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

One way is to make a hash of arrays:
my %thehash;
my $cpart = c1;  #you really get this stuff from the file, eh?
my $value = dkjdkljs;

push(@{ $thehash{$cpart} }, $value);  #while you're doing this you
might want to keep track formatting info

foreach $cpart (sort (keys(%thehash))) {print "$cpart\t"}
print "\n";
foreach $cpart (sort (keys(%thehash))){print "$thehash{$cpart}[0]\t"}
print "\n";

you'll need to put those last two statements in a loop so that you
get all the array values
    my example just gets the first (0th) array value.  You'll
probably also need to pay attention to
    formatting and the possibility that some arrays will be longer
than others  (look at printf)

hashes of arrays are covered in recipe 11.1 of the Perl Cookbook
(O'Reilly)



Reply via email to