Ask a Question related to PERL Beginners, Design and Development.
-
Dan Fish #1
Passing a variable to a package function vs. a local function
I'm a bit new to this so please bear with me...
I've written a script that uses CGI.pm something like this:
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:all);
$query = new CGI;
.....blah...blah...
&myfunc($query);
.....blah...blah...
sub myfunc{ my ($query) = @_;
$foo=$query->param("foo");
...more...blah...blah...
}
Everything works fine as is, but I'm trying to take the function "myfunc"
out and put it in a separate .pm file because I need to call it from several
cgi scripts. When I put it in the .pm file, I get something like:
Can't locate object method "param" via package "Trend" at
/usr/local/lib/perl5/site_perl/5.005/MMC/Dex.pm line 253, <INFILE> chunk
1150.
I do have:
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:all);
In the .pm file
What am I missing?
Thanks,
-Dan
Dan Fish Guest
-
Passing a ROWTYPE to a function
I'm trying to write a function that takes a %ROWTYPE as an argument. I'm just not sure how to call it from another function. This is what I tried:... -
Passing db values to function
Hello, I am creating dynamic images with corresponding checkboxes by pulling data from an Access database. The onchange event of the checkboxes... -
passing a function as a ref?
can you pass a reference to a function, then call it? How do I do it? The following does not work: function aaa(myFunc){ eval(myFunc); }... -
Passing a hash to a function
I can't seem to find in in my perl book. I'd like to pass hashes to functions #!/usr/bin/perl -wT my %someHash; $someHash{'one'} = "1";... -
Passing 'this' to a function
I would like to create a class that changes some basic attributes of a web page based on values in a database. Things like background color, font,... -
Ramprasad A Padmanabhan #2
Re: Passing a variable to a package function vs. a local function
Dan Fish wrote:
If you have name the package file as say Mypackage.pm> I'm a bit new to this so please bear with me...
>
> I've written a script that uses CGI.pm something like this:
>
> use CGI::Carp qw(fatalsToBrowser);
> use CGI qw(:all);
>
> $query = new CGI;
>
> ....blah...blah...
> &myfunc($query);
> ....blah...blah...
>
> sub myfunc{ my ($query) = @_;
> $foo=$query->param("foo");
> ...more...blah...blah...
> }
>
> Everything works fine as is, but I'm trying to take the function "myfunc"
> out and put it in a separate .pm file because I need to call it from several
> cgi scripts. When I put it in the .pm file, I get something like:
>
> Can't locate object method "param" via package "Trend" at
> /usr/local/lib/perl5/site_perl/5.005/MMC/Dex.pm line 253, <INFILE> chunk
> 1150.
>
> I do have:
> use CGI::Carp qw(fatalsToBrowser);
> use CGI qw(:all);
> In the .pm file
>
> What am I missing?
>
> Thanks,
> -Dan
>
then in your mail program you will call the function as
Mypackage::myfunc($query).
Ram
Ramprasad A Padmanabhan Guest
-
Steve Grazzini #3
Re: Passing a variable to a package function vs. a local function
On Sun, Sep 28, 2003 at 11:48:19PM -0700, Dan Fish wrote:
Either use the pure subroutine call instead of the method call.> sub myfunc{ my ($query) = @_;
> $foo=$query->param("foo");
> ...more...blah...blah...
> }
>
> Everything works fine as is, but I'm trying to take the function "myfunc"
> out and put it in a separate .pm file because I need to call it from several
> cgi scripts. When I put it in the .pm file, I get something like:
>
> Can't locate object method "param" via package "Trend" at
> /usr/local/lib/perl5/site_perl/5.005/MMC/Dex.pm line 253, <INFILE> chunk
> 1150.
Trend::myfunc( $query );
Or use the method call, and know that the first argument will
be the class/object on which the method was invoked.
package Trend;
sub myfunc {
my ($package, $query) = @_;
...
}
package main;
Trend->myfunc( $query );
--
Steve
Steve Grazzini Guest



Reply With Quote

