Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Syntax error

by Eily (Parson)
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.

Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-12-14 13:41 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (394 votes). Check out past polls.