Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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]
NodeReaper emits an eerie hum

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2017-10-19 09:32 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (252 votes). Check out past polls.