Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Not a CODE reference

Posted on 2009-05-13
23
Medium Priority
?
667 Views
Last Modified: 2013-12-25
I'm trying to link 4 radio buttons to a script using CGI.. so that if one button is selected, a certain function is carried out.

The line for calling the radio button is:

$enzyme = $query->('enzyme');

i then plan to use $enzyme for various functions:

my $re;
if   ($enzyme eq   'TRYPSIN') { $re=qr/(?<=[KR])(?!P)/; }
etc etc

but at the moment, i'm receiving the error message:

Software error:
Not a CODE reference

for the following line: $enzyme = $query->('enzyme');

Is there something i've done/am doing wrong?

Thanks.
0
Comment
Question by:StephenMcGowan
  • 12
  • 9
  • 2
23 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 24379073
splain
/usr/bin/splain: Reading from STDIN
Not a CODE reference
Not a CODE reference (#1)
    (F) Perl was trying to evaluate a reference to a code value (that is, a
    subroutine), but found a reference to something else instead.  You can
    use the ref() function to find out what kind of ref it really was.  See
    also perlref.

Are you sure
$enzyme = $query->('enzyme');
is the line that was causing the error?
0
 

Author Comment

by:StephenMcGowan
ID: 24379158
hmm unfortunately.... yeah.. i'm sure

Not a CODE reference at ./proteindigest.pl line 86. is "my $enzyme = $query->('enzyme');"

basically my $query = new CGI;

and this is the same method i used to transfer textbox data to perl, so a radio button trigger should do the same thing?
0
 
LVL 85

Expert Comment

by:ozo
ID: 24379219
I think you meant
$enzyme = $query->{'enzyme'}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 24379438
or
$enzyme = $query->param('enzyme') ;
0
 

Author Comment

by:StephenMcGowan
ID: 24379754
Thanks ozo,
almost got this now, but when i choose a protein via radio button in my HTML form:

-------------
    <label>
      <input type='radio' name='enzyme' value='TRYPSIN' id='TRYPSIN'
/>
      Trypsin</label>
    <br />
    <label>
      <input type='radio' name='enzyme' value='ENDOPROTL' id='ENDOPROTL' />
      Endoproteinase Lys-C</label>
    <br />
    <label>
      <input type='radio' name='enzyme' value='ENDOPROTA' id='ENDOPROTA' />
      Endoproteinase Arg-C</label>
    <br />
    <label>
      <input type='radio' name='enzyme' value='V8PROT' id='V8PROT' />
      V8 proteinase (Glu-C)</label><br>

------------

I'm trying to call it using the query line in Perl:

my $enzyme = $query->param('enzyme');

if   ($enzyme eq   'TRYPSIN') { $re=qr/(?<=[KR])(?!P)/; }
elsif($enzyme eq 'ENDOPROTL') { $re=qr/(?<=K)(?!P)/; }
elsif($enzyme eq 'ENDOPROTA') { $re=qr/(?<=R)(?!P)/; }
elsif($enzyme eq    'V8PROT') { $re=qr/(?<=E)(?!P)/; }
else {die "Unknown enzyme selection\n";}

When i select one of the four radio buttons on the HTML i get the "unknown enzyme selection"

So something isn't quite matching up between the two lots of code.

In  " my $enzyme = $query->param('enzyme'); " is the parameter it's searching for the id or the name on the HTML radio? have i done something obviously wrong?
0
 
LVL 85

Expert Comment

by:ozo
ID: 24379852
can you print
"Unknown enzyme selection '$enzyme'\n"
0
 

Author Comment

by:StephenMcGowan
ID: 24379885
Nope, it only leaves the two quotations :
Unknown enzyme selection '$enzyme'\n"
becomes:
Unknown enzyme selection ' '\n"

I think theres communications problem between the HTML-form and the perl script.
0
 
LVL 85

Expert Comment

by:ozo
ID: 24379939
can you print keys %{$query->{param}}
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24379943
Maybe you meant:
$query->param('enzyme');

Open in new window

0
 

Author Comment

by:StephenMcGowan
ID: 24379960
sorry how do you mean?

and where abouts in my script would " print keys %{$query->{param}} " fit into?

sorry... i'm kinda new to this, hence all the questioning :)
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24379965
Oh... i see that has already been posted, I didn't update.  Nevermind that last post.


When you submitted the form, did you select one of the enzymes?
0
 

Author Comment

by:StephenMcGowan
ID: 24379999
Hey Adam,

Yes i did, i selected Trypsin and copy/pasted some test sequence code and received "Unknown enzyme selection".. it's as though $enzyme hasn't been initialised, as when i've put it alongside the error message, it's returned a blank space (see above).
0
 
LVL 85

Expert Comment

by:ozo
ID: 24380236
is the
  if   ($enzyme eq   'TRYPSIN') { $re=qr/(?<=[KR])(?!P)/; }
in the same block as the
   my $enzyme = $query->param('enzyme');
what param names were defined?
0
 

Author Comment

by:StephenMcGowan
ID: 24380262
my $enzyme = $query->param('enzyme');

# Select an enzyme from the radio buttons on form
my $re;
if   ($enzyme eq   'TRYPSIN') { $re=qr/(?<=[KR])(?!P)/; }
elsif($enzyme eq 'ENDOPROTL') { $re=qr/(?<=K)(?!P)/; }
elsif($enzyme eq 'ENDOPROTA') { $re=qr/(?<=R)(?!P)/; }
elsif($enzyme eq    'V8PROT') { $re=qr/(?<=E)(?!P)/; }
else {die "Unknown enzyme selection '$enzyme'\n";}

is the block.

how do you find out about defined param names? if it's defined in a typical radio button, here is one button:

<input type='radio' name='enzyme' value='TRYPSIN' id='TRYPSIN'
/>
      Trypsin</label>
0
 
LVL 85

Expert Comment

by:ozo
ID: 24380302
can you print keys %{$query->{param}}
0
 
LVL 85

Expert Comment

by:ozo
ID: 24380323
How does the html form invoke the perl script?
0
 

Author Comment

by:StephenMcGowan
ID: 24380463
Think i've spotted something:

Below is the HTML code:

at the top is a form header:

<form id='form1' name='form1' method='post' action='ORFfinder.pl'>

  <label>Enter a DNA Sequence:<br>
    <textarea name='dna-textbox' id='dna-textbox' cols='45' rows='5'></textarea>
  </label>

the form id here is for textbox... textbox is linked to ORFfinder.pl therefore method='post' action='ORFfinder.pl' for textbox

BUT:

for the 4 radio buttons, they are linked to proteindigest.pl.

so would i need to create a new <form id='form1' name='form1' method='post' action='proteindigest.pl'>

followed by the radio button code?

so potentially:

<form id='form1' name='form1' method='post' action='ORFfinder.pl'>
  <label>Enter a DNA Sequence:<br>
    <textarea name='dna-textbox' id='dna-textbox' cols='45' rows='5'></textarea>
  </label>
  <p>Please select an enzyme:</p>

<form id='form2' name='form2' method='post' action='proteindigest.pl'>  
<p>
    <label>
      <input type='radio' name='enzyme' value='TRYPSIN' id='TRYPSIN'
/>
      Trypsin</label>
    <br />

even though these are two forms, would they still be displayed on the same HTML-form?
#!/usr/bin/perl
# assessment.pl   # the name of the file
 
print "Content-type: text/html
 
 
<form id='form1' name='form1' method='post' action='ORFfinder.pl'>
  <label>Enter a DNA Sequence:<br>
    <textarea name='dna-textbox' id='dna-textbox' cols='45' rows='5'></textarea>
  </label>
  <p>Please select an enzyme:</p>
  <p>
    <label>
      <input type='radio' name='enzyme' value='TRYPSIN' id='TRYPSIN'
/>
      Trypsin</label>
    <br />
    <label>
      <input type='radio' name='enzyme' value='ENDOPROTL' id='ENDOPROTL' />
      Endoproteinase Lys-C</label>
    <br />
    <label>
      <input type='radio' name='enzyme' value='ENDOPROTA' id='ENDOPROTA' />
      Endoproteinase Arg-C</label>
    <br />
    <label>
      <input type='radio' name='enzyme' value='V8PROT' id='V8PROT' />
      V8 proteinase (Glu-C)</label><br>
 
  </p>
  <p>
    <input type='submit' name='button' id='button' value='Submit' />
 
     <input type='reset' name='Reset' id='Reset' value='Reset' />
 
       <input type='button' name='Help' id='Help' value='Help' />
 
       <input type='button' name='Upload' id='Upload' value='Upload' />
 
 
    <br />
 
  </p>
</form>
 
";

Open in new window

0
 

Author Comment

by:StephenMcGowan
ID: 24380473
or would it be:

<form id='form1' name='form1' method='post' action='ORFfinder.pl'>
TEXTBOX CODE
<form id='form1' name='form1' method='post' action='proteindigest.pl'>  
RADIO BUTTON CODE
0
 

Author Comment

by:StephenMcGowan
ID: 24380537
Just tried the below following code:

I now get output but no code!

ReadingFrame1: ;
ReadingFrame2: ;
ReadingFrame3: ;
ReadingFrame4: ;
ReadingFrame5: ;
ReadingFrame6: ;

Parts:



<form id='form1' name='form1' method='post' action='ORFfinder.pl'>
TEXT BOX CODE
</form>
<form method ='post' action='proteindigest.pl'>
RADIO BUTTON CODE
</form>

Open in new window

0
 

Author Comment

by:StephenMcGowan
ID: 24380617
I think i have an idea why it's doing this...
I think now that i've activated a second cgi input variable (Textbox and Radio Buttons), It is now only taking the Radio Button input and disregarding the textbox sequence input, hence no results! (but the choice of protein works!)

I need to find a way of both features combining together, i can imagine my coding for the <forms> is wrong in my HTML-form!
0
 
LVL 85

Expert Comment

by:ozo
ID: 24381285
what is ORFfinder.pl?  
from what do you get output ReadingFrame1: ; ?
did you want to put  all the input fields into the same form?
0
 

Author Comment

by:StephenMcGowan
ID: 24382404
Ok... so far my programme is set up into three stages:

~~~~HTML form~~~~
consists of a text box and a set of 4 protein radio buttons
user enters dna code, selects a radio button, hits submit.. dna code gets sent to ORFfinder.pl
~~~~ORFfinder.pl~~~~
receives dna code from textbox
calculates the longest open reading frame for six sequences
outputs $longorfs 1-6 and fires them over to proteindigest.pl
~~~~Proteindigest.pl~~~~
picks up $longorfs 1-6 dna code and turns it into protein sequence
it then uses which-ever protein radio button was selected to initiate cutting of the sequence at certain places.

so whatever dna seq is entered into the textbox, the protein button will end up going to work on that sequence.
web-form1.jpg
0
 

Author Comment

by:StephenMcGowan
ID: 24382478
Going off above info, the HTML form:

<form id='form1' name='form1' method='post' action='ORFfinder.pl'>
 <label>Enter a DNA Sequence:<br>
TEXTBOX CODE HERE
  <p>Please select an enzyme to digest sequence:</p>

CALL TO PROTEINDIGEST ---> <form action='proteindigest.pl'>
                                  also tried <form method='post' action='proteindigest.pl'>


RADIO BUTTONS:
      <input type='radio' name='enzyme' value='TRYPSIN' id='TRYPSIN'
/>
      Trypsin</label>
    <br />
    <label>
      <input type='radio' name='enzyme' value='ENDOPROTL' id='ENDOPROTL' />
      Endoproteinase Lys-C</label>
    <br />
    <label>
      <input type='radio' name='enzyme' value='ENDOPROTA' id='ENDOPROTA' />
      Endoproteinase Arg-C</label>
    <br />
    <label>
      <input type='radio' name='enzyme' value='V8PROT' id='V8PROT' />
      V8 proteinase (Glu-C)</label><br>
SUBMIT AND OTHER BUTTONS HERE
</form>


I've attached the output in a picture below....
notice it recognises the enzyme being used but no code is coming through.
output2.jpg
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question