i'm learning perl, and i'm trying to write a program asks you to pick an amino acid and then keeps (randomly) guessing which amino acid you picked.
I would like to do it with arrays. so I declare first in the subroutine an array with the letters im looking for, then if theres a match print the variable if the match equals to variable name
if there's a match equals to variable name in subroutine how could print the variable content?
use warnings;
use strict;
print "Please type an aminoacid in one letter code; i'm going to tell you which one it is:\n";
chomp(my $aminoacid = <STDIN>);
my $aminoacid_is = guessaa ($aminoacid);
sub guessaa {
my @aminoacid_arryay = ("A","C","D","E","F","G","H","I","K","L","M","N","O","P",
"Q","R","S","T","V","W","Y");
my($A)="Alanine";
my($C)="Cysteine";
my($D)="Aspartic_acid";
my($E)="Glutamic_acid";
my($F)="Phenylalanine";
my($G)="Glycine";
my($H)="Histidine";
my($I)="Isoleucine";
my($K)="Lysine";
my($L)="Leucine";
my($M)="Methionine";
my($N)="Asparagine";
my($O)="Stop";
my($P)="Proline";
my($Q)="Glutamine";
my($R)="Arginine";
my($S)="Serine";
my($T)="Threonine";
my($V)="Valine";
my($W)="Tryptophan";
my($Y)="Tyrosine";
my($aa) = @_;
foreach $a (@aminoacid_arryay) {
if ($a eq $aa) {
print "$a","\n\n";
}
}
}
CodePudding user response:
Why it's stupid to `use a variable as a variable name'
Create a hash.
my