Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1083190]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2017-12-18 20:59 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (497 votes). Check out past polls.