GertMT has asked for the wisdom of the Perl Monks concerning the following question:

&t&tdear Monks,
while using Data::Table in a script I was trying to make use of the possibility to join tables. Below is my code and the result I was expecting but do not get via my script. Column D never appears.
Any hints are appreciated.
Gert
#!/usr/bin/perl -w use strict; use diagnostics; use Data::Table; my $t1 = new Data::Table( [ [ 1, 2, 3 ], [ 10, 20, 30 ] ], [ 'A', 'B' +], 1 ); my $t2 = new Data::Table( [ [ 1, 2, 3 ,4], [ 11, 22, 33,44 ] ], [ 'C', + 'D' ], 1 ); print $t1->csv; print "-------\n"; print $t2-;csv; print "-------\n"; $t1->join($t2,3,["A;],["C"]); print $t1->csv; exit; =head EXPECTED RESULT... A,B,D 1,10,11 2,20,22 3,30,33

Replies are listed 'Best First'.
Re: Data::Table and join
by Krambambuli (Curate) on Oct 18, 2007 at 08:42 UTC
    Looks like you need to create a new table with the join; the following seems to work ok for me:
    #!/usr/bin/perl use strict; use warnings; use Data::Table; my $t1 = new Data::Table( [ [ 1, 2, 3 ], [ 10, 20, 30 ] ], [ 'A', + 'B' ], 1 ); my $t2 = new Data::Table( [ [ 1, 2, 3 ,4], [ 11, 22, 33,44 ] ], [ 'C', + 'D' ], 1 ); print $t1->csv; print "-------\n"; print $t2->csv; print "-------\n"; my $t3 = $t1->join( $t2, 3, ["A"],["C"] ); print $t3->csv; exit;
    Good luck - and thanks for bringing Data::Table in sight, seems a nice module to play with that I didn't know so far.
      Indeed a nice module. I use it a lot in combination with GD::Graph, never had the need to join tables but it works! Thanks for your prompt reply.
      Gert
      Thanks K! Yours was the only information I could find on the data::table join operator anywhere on the internet! This is what I ended up using: $results_by_species_tabref = $results_by_species_tabref -> \ join($sp_domcount_tabref, 3, "HMM", "HMM" ); I was not enough of a perlista to recognize that "ColumnName" would give the references the operator required. The authors did not provide an example of this type this on CPAN.