in reply to Perl regex

Hi, this seems to be a trivial task in Perl (update: although your spec is not clear, really: you say "the ONE" but there may be more than one?).

From your previous question:
I am new at this and don't know where to start.

Do you want to learn Perl, or just pass your bio class?

This is the place to learn Perl.

See perlintro, perlretut.

If you just have other people do your work for you, you won't learn anything. Scientists aren't like that.

Update: deleted example solution as I am not sure I understand the spec after follow-up post from OP...


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Perl regex
by Nicpetbio23! (Acolyte) on Jul 12, 2017 at 14:47 UTC
    Its just ONE the "the" was a typo.

      $ perl -nE '/([^\(]+)\((.*)\)/ and $1 ne $2 and ++$seen{$2} < 2 and sa +y "$1 : $2"' raw_data.txt Metan1_4283 : Metac1_3189 MagorCD156_00067621 : MagorUS71_00075311 Phaca1_206503 : Phchr2_2932727 Thite2_36710 : Thiar1_121068 Spoth2_47778 : Thiar1_767720 Micmi1_311120 : Micmi1_478558 Micmi1_478558 : Micmi1_311120
      (Don't use it until you can explain it! Questions welcome.)

      The way forward always starts with a minimal test.
        I think I understand most of it. Except -nE and ++ $seen{$2}.
        perl : load perl -nE : $1 stands for : ([^\(]+) for example Metan1_4283 in Metan1_4283(Metac1 +_3189) $2 stands for : \n((.*)\) for example (Metac1_3189) in Metan1_4283(Met +ac1_3189) $1 ne $2 : Means if first pattern does not match second pattern. ++ $seen{$2} : < 2 : less than 2. say "$1 : $2"' : prints out into two columns. raw_data.txt : path to file goes here.