Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-18-2008, 05:24 AM
|
#1
|
|
LQ Newbie
Registered: Oct 2008
Location: Cardiff, Wales
Distribution: Jaunty
Posts: 20
Rep:
|
perl: simple one line replacement, simple error message!
Just been trying out some simple perl to get me started, straight from a book and i keep getting back a syntax error back for the replacement line in:
Code:
sub translate {
my ($mrna) = @_;
my $pro = " ";
while ($mrna =~s/(...)//){
$pro = $pro . $codonMap{$1};
}
return $pro;
}
in the book ive got it shows the ~ as superscript but ive been assured that that key doesnt exist so not sure why it doesnt like it.

|
|
|
|
11-18-2008, 06:20 AM
|
#2
|
|
Member
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892
Rep:
|
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.
|
|
|
|
11-18-2008, 07:33 AM
|
#3
|
|
Member
Registered: May 2007
Distribution: Debian
Posts: 754
Rep:
|
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:
Code:
perl -Mdiagnostics script_name
|
|
|
|
11-18-2008, 05:44 PM
|
#4
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 15,000
|
Always use
use strict;
use warnings;
at the top of your programs it'll help a lot. BTW, an alternate for 'use warnings;' is to use the -w switch as in
#!/usr/bin/perl -w
as the first line of your code (adjust to match your env).
In this case,
use diagnostics;
as well is good for debugging. Showing us the exact error msg and the input data would really help.
|
|
|
|
11-19-2008, 08:55 AM
|
#5
|
|
LQ Newbie
Registered: Oct 2008
Location: Cardiff, Wales
Distribution: Jaunty
Posts: 20
Original Poster
Rep:
|
error message:
The error message reads as this:
Code:
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.
|
|
|
|
11-19-2008, 11:49 AM
|
#6
|
|
Senior Member
Registered: May 2005
Posts: 4,397
|
Quote:
Originally Posted by pwd_pwd_omg_pwd
The error message reads as this:
Code:
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.
|
|
|
|
11-19-2008, 11:53 AM
|
#7
|
|
Senior Member
Registered: May 2005
Posts: 4,397
|
deleted by Sergei.
|
|
|
|
11-19-2008, 11:57 AM
|
#8
|
|
Senior Member
Registered: May 2005
Posts: 4,397
|
Quote:
Originally Posted by pwd_pwd_omg_pwd
The error message reads as this:
Code:
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.
|
You apparently have missing trailing '/' here:
$rna =~tr/ACGT/UGCA;
, i.e. I think it should be
$rna =~tr/ACGT/UGCA/;
|
|
|
|
11-19-2008, 12:53 PM
|
#9
|
|
Member
Registered: May 2007
Distribution: Debian
Posts: 754
Rep:
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:46 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.
|
Latest Threads
LQ News
|
|