Click here to get back home

Can't call method on an undefined value at

 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
Can't call method on an undefined value at richardlsmith 06-27-2005
Posted by richardlsmith on June 27, 2005, 2:56 pm
Please log in for more thread options


I want to reference a variable in a module that was created in the
module consuming program.

----------
The module looks like this:

#! /usr/bin/perl -w

package Module;
require Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw(f1);
our $VERSION = 1.00;

sub f1 {
print "$v1\n";
}

1;

----------
The consuming Perl script looks like this:

#! /usr/bin/perl -w

use Module;

$v1 = "v1";

f1();

----------
Any suggestions on how I make this work?



Posted by John Bokma on June 27, 2005, 10:32 pm
Please log in for more thread options




> The consuming Perl script looks like this:
>
> #! /usr/bin/perl -w
>
> use Module;
>
> $v1 = "v1";
>
> f1();
>
> ----------
> Any suggestions on how I make this work?

I would use OO + a setter method.

tip:

drop -w, and use strict; use warnings;


--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html



Posted by Gunnar Hjalmarsson on June 28, 2005, 12:16 am
Please log in for more thread options


richardlsmith wrote:
> I want to reference a variable in a module that was created in the
> module consuming program.

<snip>

> Any suggestions on how I make this work?

Use its fully qualified name:

sub f1 {
print "$::v1\n";
}

See "perldoc perlmod".

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


Similar ThreadsPosted
Crypt::CBC Can't call method "blocksize" on unblessed reference July 12, 2004, 10:01 am
"Undefined subroutine" November 21, 2004, 8:48 pm
Getting "undefined sysmbol February 8, 2005, 8:12 am
GD-1.38: Undefined symbol: .__fixsfsi July 12, 2004, 10:43 am
undefined symbol: gdImageCreateFromGif June 14, 2007, 1:00 pm
Win32::Ole and Call by reference October 22, 2004, 10:06 am
How to call PL/SQL procs using Oraperl ? December 8, 2004, 5:22 pm
How can I call MFC functions from Perl July 19, 2005, 9:46 pm
HTTP::Response decoded_content is undefined March 28, 2007, 8:04 am
LibXML "Undefined namespace prefix" July 2, 2007, 5:42 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap