in reply to how to access the data to one to many relationship

I would use split and regular expressions, too, but in a less complicated way:
#!/usr/bin/perl use warnings; use strict; my $input = 'tar : ERGC [1] | ALX5 [2] | PT2 [3] | PRTD [4] act: Ago + [1] : Inhibit [2,3,4]'; my ($left, $right) = split /act:/, $input; my %num2left; while ($left =~ /(\S+) \[([0-9])\]/g) { $num2left{$2} = $1; } while ($right =~ /(\S+) \[([0-9,]+)\]/g) { my ($target, @indices) = ($1, split /,/, $2); for my $i (@indices) { print "$i $num2left{$i}\t$target\n"; } }

Output:

1 ERGC Ago 2 ALX5 Inhibit 3 PT2 Inhibit 4 PRTD Inhibit
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: how to access the data to one to many relationship
by Anonymous Monk on Mar 23, 2015 at 12:29 UTC
    ITs my fault that I didn't add the other variations in input.
    my $input = 'tar : ERGC act : Ago'
    That's with out indices. With this I am missing those sets which doesn't have a reference. How should I fix them? Using another while loop to capture those without reference is not working. Also, I tried if else condition to check whether the targets have reference before passing them to the while loops. Doesn't help either. Thanks
      Oh, come on:
      if (not %num2left) { $left =~ s/tar : //; print "NOINDEX\t$left\t$right\n"; }
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Now move it over to the other corner ... by the plants.