Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by BrowserUk (Patriarch)
on Apr 22, 2014 at 15:20 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-18 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found