Undefined subroutine &main::param called

P

paul.hopgood

I need help solving a subroutine error in my Pearl script.
Here is the error I'm getting:
binmode() on closed filehandle SAVE at /recording.pl line 12.
Undefined subroutine &main::param called at /recording.pl line 13.

Below is my script:

#!/usr/bin/perl -w

use strict;
$|++;

my $pathToRecordings="http://www.deathnotify.com/recordings";
my $newRecording = "test.wav";



open (SAVE, "> $pathToRecordings/recordings");
binmode(SAVE);
while (read(param("voiceMessage"),$newRecording,1024))
{ print SAVE $newRecording; }
close(SAVE);

Any suggestions would be most appreciated.
Thanks!
-Paul
 
K

Krishna Chaitanya

Hi Paul,

The error messages by Perl are pretty informative, actually...
binmode() on closed filehandle SAVE at /recording.pl line 12.

This could be due to open failing to create the SAVE filehandle. Check
the syntax and file-name/path you are trying to open. Use the "or die"
idiom. (i.e. open(SAVE,.....) or die "Could not open SAVE on .... ")
Undefined subroutine &main::param called at /recording.pl line 13.

That's because there is no function called param written by you in
this script. And neither does param sound like a Perl built-in (check
Functions side-tab in http://perldoc.perl.org for a list of Perl built-
in functions). So Perl couldn't locate the param call and complained.

You could've known more info by using warnings and strict as follows:

use warnings;
use strict;

Always use these as they save a lot of headache....hope this helps.

-Chaitanya
 
D

Dave Weaver

On Tue, 17 Feb 2009 23:16:25 -0800 (PST),
I need help solving a subroutine error in my Pearl script.
Here is the error I'm getting:
binmode() on closed filehandle SAVE at /recording.pl line 12.
Undefined subroutine &main::param called at /recording.pl line 13.

Below is my script:

#!/usr/bin/perl -w

use strict;
$|++;

my $pathToRecordings="http://www.deathnotify.com/recordings";
my $newRecording = "test.wav";

You don't refer to $newRecording anywhere in your script.

open (SAVE, "> $pathToRecordings/recordings");

You should *always* check the return value from open() - it'll tell
you if the open worked or failed (and why it failed). Also it's better
to use lexical filehandles and the 3-argument form of open. Like this:

open my $save, '>', $filename
or die "Can't write to '$filename' because $!";

You're trying to write to a file called
"http://www.deathnotify.com/recordings/recordings"
It appears as though you're trying up write to some website.
open() reads or writes to files on the local filesystem, and can't
write to URLs.

If you are trying to send the file to a different computer, you
need to use some other method to do it. FTP, for example, using the
Net::FTP module.

binmode(SAVE);

You got your 1st error messge here, because the open() failed (and
you didn't notice), so SAVE doesn't refer to an open file.
while (read(param("voiceMessage"),$newRecording,1024))

Your script has no param() function, yet here you are trying to call
it, which is the reason for your second error message.

Were you thinking of the param() function provided by the CGI module?
Is your script running as a CGI script on a webserver? If so, perhaps
you forgot
use CGI;
at the start of your script.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top