Can"t call method <function> on an undefined value at <module>

Can"t call method <function> on an undefined value at <module>

am 27.06.2005 22:56:59 von richardlsmith

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?

Re: Can"t call method <function> on an undefined value at <module>

am 27.06.2005 23:16:00 von Gunnar Hjalmarsson

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



> 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

Re: Can"t call method <function> on an undefined value at <module>

am 27.06.2005 23:32:59 von John Bokma

"richardlsmith" wrote:


> 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