Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Syntax error

by Eily (Deacon)
on Feb 10, 2014 at 00:16 UTC ( #1074179=note: print w/ replies, xml ) Need Help??


in reply to Syntax error

Just before option 2, you have written }end if. There's no such thing as an endif in Perl, you forgot to make it a comment :)

I didn't read your whole script. One advice though, instead of ($base eq 'g' or $base eq 'G') you can write (lc $base eq 'g') (see lc). That should be the easy enough to understand. Then, if you want to try matching $base against several values you can write (grep { lc $base eq $_ } 'a', 'c', 'g', 't'). Read grep on that.

A lot of Perl users would use regular expressions instead of grep and lc, you can have a look at perlretut on the subject, if you feel adventurous.


Comment on Re: Syntax error
Select or Download Code
Re^2: Syntax error
by tobyink (Abbot) on Feb 10, 2014 at 00:34 UTC

    Or better still, lowercase $base as soon as you set it:

    $base = lc substr($sequence, $position, 1);

    Then comparisons can just be like:

    if ($base eq 'g' or $base eq 't') { ... }

    ... and you don't need to worry about capital letters at all.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

      Yeah, I guess it might have been a better idea to look at least a little more through the code before giving advice :). I just commented on the big obvious thing that jumped on my face, but I'm sure there is more than one way to improve it (that does sound perlish already :D).

Re^2: Syntax error
by Anonymous Monk on Feb 10, 2014 at 01:35 UTC

    Right. Furthermore, the perlish way is to avoid iterating over characters, if possible. Consider this:

    my $A_count = ($sequence =~ tr/Aa/Aa/);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-12-28 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls