Professional Web Applications Themes

Can't call method <function> on an undefined value at <module> - PERL Modules

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?...

  1. #1

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

    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?

    richardlsmith Guest

  2. #2

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

    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: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
    Gunnar Hjalmarsson Guest

  3. #3

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

    "richardlsmith" <richardlsmith2> 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: [url]http://johnbokma.com/perl/[/url]
    Perl programmer available: [url]http://castleamber.com/[/url]
    Happy Customers: [url]http://castleamber.com/testimonials.html[/url]

    John Bokma Guest

Similar Threads

  1. #40742 [NEW]: Call to undefined function preg_replace()
    By mirko dot viviani at gmail dot com in forum PHP Bugs
    Replies: 1
    Last Post: March 6th, 09:13 PM
  2. #39658 [NEW]: COM Error: Call to undefined method
    By yuri at php dot ru in forum PHP Bugs
    Replies: 1
    Last Post: November 28th, 09:57 AM
  3. #39658 [Opn->Csd]: COM Error: Call to undefined method
    By yuri at php dot ru in forum PHP Bugs
    Replies: 0
    Last Post: November 28th, 09:51 AM
  4. How do I call an outer function from a class method function?
    By Phil Powell in forum PHP Development
    Replies: 5
    Last Post: October 16th, 09:56 AM
  5. Call to undefined function: myformvalidate()
    By Marcus in forum PHP Development
    Replies: 2
    Last Post: July 4th, 08:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139