Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Can you help me with these one-liners?

by BrowserUk (Pope)
on Apr 22, 2014 at 15:20 UTC ( #1083190=note: print w/ replies, xml ) Need Help??

in reply to Can you help me with these one-liners?

Example1: perl -e 'while(<>) {if($_=~/^>/) {print $_;} else {$_=~tr/ATCG/TAGC/; +print $_;}}' FILE

Use -n to replace the while loop:

perl -nle 'if($_=~/^>/) {print $_;} else {$_=~tr/ATCG/TAGC/; print $_; +}' FILE

Do away with the unnecessary explicit references to $_:

perl -nle 'if(/^>/) {print;} else { tr/ATCG/TAGC/; print; }' FILE

Recognise that every line is being printed, so -p can replace the explicit print statements:

perl -ple 'if(/^>/) { ; } else { tr/ATCG/TAGC/; }' FILE

Rearrange to do away with the empty if body:

perl -ple 'tr/ATCG/TAGC/ unless( /^>/ );' FILE

UPDATE: a final step:

perl -ple '/^>/ or tr/ATCG/TAGC/' FILE

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Comment on Re: Can you help me with these one-liners?
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2015-11-27 09:41 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (722 votes), past polls