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

I have a file.fasta and i need to find how many and in which lines i can find GL*{3}G..in this file, can i have some help?

Replies are listed 'Best First'.
Re: some help
by GrandFather (Saint) on Nov 29, 2014 at 09:39 UTC

    Sure you can have some help. Take a look in Tutorials and perldoc for some Perl getting started info. When you have spent some time trying to make your first script work, but before you get completely frustrated, come ask us for some help with your script. you'll need to show us what you've tried and tell us where you are having trouble. See I know what I mean. Why don't you? for some hints about how to best ask for help.

    Perl is the programming world's equivalent of English
Re: some help
by Corion (Patriarch) on Nov 29, 2014 at 09:48 UTC

    If GL*{3}G is supposed a regular expression, maybe you meant GL.{3}G? Your string makes no sense in Perl, and if you want to allow 3 arbitrary characters, use .{3}.

Re: some help
by AnomalousMonk (Archbishop) on Nov 29, 2014 at 13:11 UTC

    Further to Corion's post:  * is a regex quantifier meaning "zero or more" of something, and  {3} is another quantifier meaning "exactly three". As stated, they don't go together. In addition to perlretut linked by Corion, please also see perlre and perlrequick.

Re: some help
by davido (Cardinal) on Nov 29, 2014 at 17:54 UTC

    This will find the literal text "GL*{3}G" in your fasta file, and will print the line number as well as the actual line where it was found. If that trigger text was supposed to be a regular expression you'll need to show us an actual regular expression that is Perl compatible.

    perl -nle 'm/\QGL*{3}G\E/ && print "$.: $_"' file.fasta

    If you had something else in mind, please post the code you've started with so that we can help you with it. Also post sample input and output, and don't forget to wrap code and IO samples in code tags per Writeup Formatting Tips.


    Dave