Click here to get back home

referencing a param and $self in an OO subroutine

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
referencing a param and $self in an OO subroutine Marc 03-20-2007
Posted by Sherm Pendley on March 20, 2007, 5:55 pm
Please log in for more thread options



> I'm working on making an object oriented module in Perl for the first
> time and have run into an error that I'm having trouble with:
> "Can't call method "workbook" without a package or object
> reference..."
>
> sub CreateWorksheet
> {
> my $self = @_;

Here's the problem. This assigns the number of elements in @_ to the $self
variable. So $self is not an object, it's 2.

> #if (@_) { my $sheetname = shift; }
> my $sheetname = shift;

This pops the first element off of @_ - which is what you wanted in $self.

Another way to write these lines:

my ($self, $sheetname) = @_;

Another:

my $self = $_[0];
my $sheetname = $_[1];

And another:

my $self = shift;
my $sheetname = shift;

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net

Similar ThreadsPosted
CGI param persists when used with FastCGI October 6, 2005, 2:09 pm
MIME::EncWords charset param February 20, 2007, 7:03 pm
"Undefined subroutine" November 21, 2004, 8:48 pm
catch_int\catch_hup subroutine February 25, 2005, 8:51 am
Options for passing Hash to a subroutine. March 30, 2005, 7:39 pm
Perl Tk:Scheduler command called subroutine fails to talk to tk widgets January 31, 2007, 2:05 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap