Solved

Not a CODE reference

Posted on 2009-05-13
23
637 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 84

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 84

Expert Comment

by:ozo
ID: 24379219
I think you meant
$enzyme = $query->{'enzyme'}
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 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 84

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 84

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 84

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 84

Expert Comment

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

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 84

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to dynamically set the form action using jQuery.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now