Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Adding values in a variable

by Laurent_R (Canon)
on Oct 15, 2017 at 20:37 UTC ( [id://1201414]=note: print w/replies, xml ) Need Help??


in reply to Adding values in a variable

Hi bisimen,

your error is in this line:

$mass .= "$mass_values{$codon}\n";
This line concatenates all the masses (interleaved with a new line), whereas you want to sum them up. So, in the end, you get a large string with all the masses, each on its own line. Just replace concatenation with addition:
$mass += $mass_values{$codon};
and your first program should do what you want, without the need for the second one.

There are other improvements that could be made: use strict, don't use no warnings 'uninitialized'; just to silence the warnings, but try to remove the warnings by understanding where they come from (possibly a new line character at the end of your string in the file), chomp the line you read from the input file, use split to get the individual letters of the protein string (see choroba's example above).

Replies are listed 'Best First'.
Re^2: Adding values in a variable
by bisimen (Acolyte) on Oct 16, 2017 at 09:34 UTC
    Thanks! This was helpful. And yes, using chomp on the protein string did remove the warning.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-26 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found