Undefined subroutine &main::param called

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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");
   while (read(param("voiceMessage"),$newRecording,1024))
      { print SAVE $newRecording; }

Any suggestions would be most appreciated.

Re: Undefined subroutine &main::param called

Hi Paul,

The error messages by Perl are pretty informative, actually...

Quoted text here. Click to load it

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 .... ")

Quoted text here. Click to load it

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.


Re: Undefined subroutine &main::param called

On Tue, 17 Feb 2009 23:16:25 -0800 (PST),
Quoted text here. Click to load it

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

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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.

Site Timeline