Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

errors with explicit package name 1

Status
Not open for further replies.

JohnLucania

Programmer
Oct 10, 2005
96
US
#! /usr/bin/perl

use warnings;
use strict;
use CGI (':standard');

my $title = '1000 Sequences';
print header,
start_html( $title ),
h1( $title );

sub random_dna {
my $length = shift;
my @charlist = ( 'A' , 'C' , 'T', 'G' );
my $random;
$random .= $charlist[ int rand( @charlist ) ] for ( 1 .. 1000 );
return($random);
}

sub random_protein {
my $length = shift;
my @charlist = ('Ala', 'Arg', 'Asn', 'Asp', 'Cys', 'Gln', 'Glu', 'Gly', 'His', 'Ile', 'Leu', 'Lys', 'Met', 'Phe', 'Pro', 'Ser', 'Thr','Trp', 'Tyr', 'Val', 'Asx', 'Glx', 'Xaa');
my $random;
$random .= $charlist[ int rand( @charlist ) ] for ( 1 .. 1000 );
return($random);
}
my $q=new CGI;
my $dna=$q->param('Seq');
print random_dna() if $dna eq 'DNA';
print random_protein() if $dna eq 'Protein';
hr();

my $url = url();
my $seq = param( 'Seq' ) || 'unknown';
print start_form( -method => 'GET' , action => $url ),
p( "What sequence do you want: " . radio_group( -name => 'Seq' ,
-values => [ 'DNA' , 'Protein' ] )),
p( submit( -name => 'submit' , value => 'Submit' )),
end_form(),
end_html();

why are these errors showing up?

"my" variable $seq masks earlier declaration in same scope at ./DNAProteinSeq.cgi line 34.
Global symbol "$dna" requires explicit package name at ./DNAProteinSeq.cgi line 29.
Global symbol "$dna" requires explicit package name at ./DNAProteinSeq.cgi line 30.

jl
 
the script works fine for me. These two lines:

my $q=new CGI;
my $dna=$q->param('Seq');

could just be written as:

my $dna=param('Seq');

you don't need a CGI object since you are using the standard method:

use CGI (':standard');

these lines aren't doing anything in your script:

my $length = shift;

you're not importing any arguments into your sub routines but maybe it's still a work in progress.
 
you might find this alternative code of interest:

Code:
#!/usr/bin/perl

use warnings;
use strict;
use CGI (':standard');

my $title = '1000 Sequences';
my $dna = param('Seq');
my @dna = ( 'A' , 'C' , 'T', 'G' );
my @protien = ('Ala', 'Arg', 'Asn', 'Asp', 'Cys', 'Gln', 'Glu', 'Gly', 'His', 'Ile', 'Leu', 'Lys', 'Met', 'Phe', 'Pro', 'Ser', 'Thr','Trp', 'Tyr', 'Val', 'Asx', 'Glx', 'Xaa');
my %commands = (
   DNA => sub { print $dna[ int rand( @dna ) ] for ( 1 .. 1000 )},
   Protein => sub {print $protien[ int rand( @protien ) ] for ( 1 .. 1000 )}
);
print header,
start_html( $title ),
h1( $title );
$commands{$dna}->();
print hr();
print start_form( -method => 'POST' , action =>  url()),
p( "What sequence do you want: "  . radio_group( -name   => 'Seq' ,
                                                 -values => [ 'DNA' , 'Protein' ] )),
p( submit( -name => 'submit' , value => 'Submit' )),
end_form(),
end_html();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top