Your main issue is in the lines

$groups{$_}{left} = $rxn[0] for @left_els; $groups{$_}{right} = $rxn[0] for @right_els;

If a group value turns up more than once, you overwrite the key value that you stored before. I am lazy, so here is a script that I think does what you want (rather than fixing yours). I tried to keep it as close as possible to yours so you can take parts and paste it into yours.

use strict; use warnings; my %groups; #my @keys; while(<DATA>){ s/(\s|#)\d\s/$1/g; s/\s//g; my( $key, $left, $right ) = /^([^#]+).*#(.*)<=>(.*)/; $groups{$_}{left }{$key} = 1 for split /\+/, $left; $groups{$_}{right}{$key} = 1 for split /\+/, $right; #push @keys, $key; } for my $grp ( values %groups ) { for my $left ( keys %{ $grp->{left} } ) { for my $right ( keys %{ $grp->{right} } ) { print "$left <=> $right\n"; } } } __DATA__ R00009MM#R00009#2 C00027MM <=> C00007MM + 2 C00001MM R00014MM#R00014#C00022MM + C00068MM + C00080MM <=> C05125MM + C00011MM R00081MM#R00081#C00007MM + 4 C00126MM + 8 C00080MM <=> 4 C00125MM + 2 +C00001MM + 4 C00080Cyto R00086MM#R00086#C00008MM + C00009MM + 7 C00080Cyto <=> C00002MM + C000 +01MM + 7 C00080MM R00094MM#R00094#2 C00051MM + C00003MM <=> C00127MM + C00004MM + C00080 +MM

UPDATE: Just realized that @keys is not used, so I commented those two lines.


In reply to Re: Mapping issues by hdb
in thread Mapping issues by filipo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.