Hi,
You can use a HoH
my $result = { 'A' => { 1 => 1, 2 => 1, 7 => 1, 10 => 1, ... }, 'B' => { ... }, ... };
Using something like this for generating it:
open my $fh, '<', $filename; while (<$fh>) { chomp; my ($id, @numbers) = split; for my $number (@numbers) { $result->{$id}{$number} = 1; } }
Update:
Later if you want to output it, you could do something like this:
my %unique_numbers = (); for (values %$result) { for my $number (keys %$_) { $unique_numbers{$number} = 1; } } my @numbers = sort {$a <=> $b} keys %unique_numbers; open my $out_fh, '>', $output_filename; print $out_fh "IDs @numbers\n"; for my $id (sort keys %$result) { my @fields = $id; for my $number (@numbers) { if (exists $result->{$id}{$number}) { push @fields, 1; } else { push @fields, 0; } } my $string = join " ", @fields; print $out_fh "$string\n"; }
I know, it's not so nice, but... if it's a throw away problem...
For the thing of having a fancy output, you can use format or take a look on CPAN, I remember to see some modules for producing a tabular ASCII output
Update 2:
Yes GrandFather, you're right, I just saw the "interval" thing :-)
Regards,
In reply to Re: construct a matrix by different intervals
by fmerges
in thread construct a matrix by different intervals
by mozart
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |