Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: add letters to the begin of the sentence

by kcott (Abbot)
on Sep 12, 2013 at 21:46 UTC ( #1053800=note: print w/ replies, xml ) Need Help??


in reply to add letters to the begin of the sentence

G'day intect,

This technique should do what you want:

$ perl -Mstrict -Mwarnings -e ' my @fasta = (">dddd\n", "abcdef\n", ">eeee\n", "bcdef\n"); for (@fasta) { print "aaaa" unless /^>/; print; } ' >dddd aaaaabcdef >eeee aaaabcdef

Using your filehandles, that would be:

while (<$input_fh>) { print $output_fh 'aaaa' unless /^>/; print $output_fh $_; }

If the ACGAGTGCGT in your code is supposed to be the aaaa in your description, then just make the appropriate substitution. If it isn't, a clarification would be useful.

-- Ken


Comment on Re: add letters to the begin of the sentence
Select or Download Code
Re^2: add letters to the begin of the sentence
by intect (Initiate) on Sep 13, 2013 at 13:18 UTC
    Thank you, Ken. It works very well. Would you help me identify the problem in my script. I moved the print after unless block but it still does not work.
      "Thank you, Ken. It works very well."

      You're welcome.

      "Would you help me identify the problem in my script."

      Happy to.

      "I moved the print after unless block but it still does not work."

      Unfortunately, that doesn't help me to help you. What exactly did you move? Where precisely did you move it to? What does "it still does not work" mean?

      You need to provide code along with expected results, actual results, and any error or warnings messages. This is all described in more detail in the "How do I post a question effectively?" guidelines.

      Here's what choroba was referring to:

      $ perl -Mstrict -Mwarnings -e ' my @fasta = (">dddd\n", "abcdef\n", ">eeee\n", "bcdef\n"); for (@fasta) { unless (/^>/) { s/^/ACGAGTGCGT/; } print; } ' >dddd ACGAGTGCGTabcdef >eeee ACGAGTGCGTbcdef

      That may give you your answer. If not, post the requested information so that we can provide genuine help as opposed to guesswork.

      -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1053800]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-08-31 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls