perl: simple one line replacement, simple error message!
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Seeing the complete regex used in the substitution, along with the kinds of input the function is expected to take and the expected output, might help.
Last edited by taylor_venable; 11-18-2008 at 06:28 AM.
It wouldn't hurt to post the actual error message. As a general tip, try running the script with use diagnostics; in effect. You can put that up at the top of your script instead of use warnings; - it will give you more verbose error messages. Or you can run the script this way:
syntax error at transprog.pl line 18, near "while ($mrna ~=s/("
(Might be a runaway multi-line // string starting on line 10)
Global symbol "$pro" requires explicit package name at transprog.pl line 18.Global symbol "$pro" requires explicit package name at transprog.pl line 18.Execution of transprog.pl aborted due to compilation errors.
and it is still saying it after I have changed the replacement line, which i thought was the whole problem. the use warnings didnt say anything new than it was before and the -Mdiagnostics said: its probably a syntax error.
The script has a few other parts and subs to it, but essentially this sub will take an inputed mRNA seq AGCUAGUCGCUGCAGUCUGCAUGC... and look up each 3 letters to a data set at the end of the format:
Ala GCU, GCC, GCA, GCG
Leu UUA, UUG, CUU, CUC, CUA, CUG
Arg CGU, CGC, CGA, CGG, AGA, AGG
Lys AAA, AAG
etc.
and list the amino acids.
AlaLeuArgLys...
The first part of the code reads:
Quote:
#!/usr/bin/perl
use strict;
use diagnostics;
my %codonMap;
## translates DNA strings to RNA
sub transcribe {
my ($dna) = @_;
my $rna = scalar reverse $dna;
$rna =~tr/ACGT/UGCA; ##10
return $rna;
}
## translates mRNA strings to proteins
sub translate {
my ($mrna) = @_;
my $pro = " ";
while ($rna ~=s/(...)//){ ##18
$pro = $pro . $codonMap{$1};
}
return $pro;
}
(10 and 18 are the lines it mentions in the error btw)
thanks for the help guys.
Last edited by pwd_pwd_omg_pwd; 11-19-2008 at 09:00 AM.
Reason: missed a bit out.
syntax error at transprog.pl line 18, near "while ($mrna ~=s/("
(Might be a runaway multi-line // string starting on line 10)
Global symbol "$pro" requires explicit package name at transprog.pl line 18.Global symbol "$pro" requires explicit package name at transprog.pl line 18.Execution of transprog.pl aborted due to compilation errors.
and it is still saying it after I have changed the replacement line, which i thought was the whole problem. the use warnings didnt say anything new than it was before and the -Mdiagnostics said: its probably a syntax error.
The script has a few other parts and subs to it, but essentially this sub will take an inputed mRNA seq AGCUAGUCGCUGCAGUCUGCAUGC... and look up each 3 letters to a data set at the end of the format:
Ala GCU, GCC, GCA, GCG
Leu UUA, UUG, CUU, CUC, CUA, CUG
Arg CGU, CGC, CGA, CGG, AGA, AGG
Lys AAA, AAG
etc.
and list the amino acids.
AlaLeuArgLys...
The first part of the code reads:
(10 and 18 are the lines it mentions in the error btw)
thanks for the help guys.
Try to make our lives easier - post the code processed by 'cat -n', so we'll be able to see line numbers and related them to the ones in error messages.
Last edited by Sergei Steshenko; 11-19-2008 at 11:55 AM.
syntax error at transprog.pl line 18, near "while ($mrna ~=s/("
(Might be a runaway multi-line // string starting on line 10)
Global symbol "$pro" requires explicit package name at transprog.pl line 18.Global symbol "$pro" requires explicit package name at transprog.pl line 18.Execution of transprog.pl aborted due to compilation errors.
and it is still saying it after I have changed the replacement line, which i thought was the whole problem. the use warnings didnt say anything new than it was before and the -Mdiagnostics said: its probably a syntax error.
The script has a few other parts and subs to it, but essentially this sub will take an inputed mRNA seq AGCUAGUCGCUGCAGUCUGCAUGC... and look up each 3 letters to a data set at the end of the format:
Ala GCU, GCC, GCA, GCG
Leu UUA, UUG, CUU, CUC, CUA, CUG
Arg CGU, CGC, CGA, CGG, AGA, AGG
Lys AAA, AAG
etc.
and list the amino acids.
AlaLeuArgLys...
The first part of the code reads:
(10 and 18 are the lines it mentions in the error btw)
Two other problems that I can see: on line 18 (1) you've written ~= instead of =~ and (2) you're using $rna in a subroutine where it isn't visible. Did you mean $mrna there (from line 16) or did you want $rna to be available to both subroutines?
As a general rule, the line number of the error from Perl is where the error gets caught. You will need to backtrack up from there, since the real problem is (often) somewhere earlier. Here's a quick example:
Code:
#!/usr/bin/perl
use strict;
use warnings;
my $foobar
print "$foobar\n";
The problem is the missing semicolon in line five, but Perl will tell me that the error was caught at the print statement in line 7 (even though the print statement itself is fine).
Last edited by Telemachos; 11-19-2008 at 12:55 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.