in reply to Re: Perl regex
in thread Perl regex

Its just ONE the "the" was a typo.

Replies are listed 'Best First'.
Re^3: Perl regex
by 1nickt (Canon) on Jul 12, 2017 at 15:09 UTC

    $ 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.

        Hi, so one of the greatest things about Perl is its documentation. You can find answers yourself!

        I Googled for 'perl ++ operand' and got perlop - Perl operators and precedence > Auto increment and Auto decrement. (Here we increment the value stored in %seen for each key *before* making sure that we haven't already seen this key by checking that the value *after* incrementing is less than 2. Also makes use of Perl's autovivification.)

        For -n and -E and all other command line switches for the perl executable, see perlrun - how to execute the Perl interpreter.

        Note that the doc I first pointed you to, perlintro, contains links to all these docs in the overview it gives of each topic. Have you yet allocated a couple of hours of your time to read that document? Seems fair, when you are getting other Monks to give of their time to you.


        The way forward always starts with a minimal test.