Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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]
[Corion]: Yeah, you need bool to get a true value, and the rest to return the other value ;)
[choroba]: perl -wE '{package o; use Tie::Scalar; use parent -norequire => "Tie::StdScalar" ;sub FETCH { "x" x int rand 2}} tie my $x, "o" ; say $x for 1 .. 10'
[choroba]: for complete ness

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2017-07-27 13:56 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (414 votes). Check out past polls.