Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > What wrong with my module?

Reply
Thread Tools

What wrong with my module?

 
 
Great Deals
Guest
Posts: n/a
 
      09-23-2003
I put a file called test.pm in the same dir as test.pl

test.pm:
#perl
package test;
sub getit (){
return time;
}

test.pl:
#perl
use test;

$ab= test::getit();
print "$ab\n";

the error is:
Undefined subroutine &test::getit called at test.pl line 4.
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-23-2003
Great Deals wrote:
> I put a file called test.pm in the same dir as test.pl
>
> test.pm:
> #perl
> package test;
> sub getit (){
> return time;
> }


Ensure that the module returns a true value by adding

1;

to the bottom.

> test.pl:
> #perl


Try adding

use lib '.';

here.

> use test;
>
> $ab= test::getit();
> print "$ab\n";
>
> the error is:
> Undefined subroutine &test::getit called at test.pl line 4.


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

 
Reply With Quote
 
 
 
 
Sam Holden
Guest
Posts: n/a
 
      09-23-2003
On 22 Sep 2003 20:08:03 -0700,
Great Deals <> wrote:
> I put a file called test.pm in the same dir as test.pl
>
> test.pm:
> #perl
> package test;
> sub getit (){
> return time;
> }
>


Since the temp.pm above doesn't return a true value either aren't
getting the error you specifiy below, or you aren't using the code
you posted.

> test.pl:
> #perl
> use test;
>
> $ab= test::getit();
> print "$ab\n";
>
> the error is:
> Undefined subroutine &test::getit called at test.pl line 4.


There's not much point in fixing some random code that you aren't
actually using.

test.pm doesn't contain what you claim it does, or a different
test.pm is getting included than the one you think is...

--
Sam Holden

 
Reply With Quote
 
Keith Keller
Guest
Posts: n/a
 
      09-23-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In article <>, Sam Holden wrote:

> There's not much point in fixing some random code that you aren't
> actually using.
>
> test.pm doesn't contain what you claim it does, or a different
> test.pm is getting included than the one you think is...


If the latter, then certainly Great Deals could be using the
code he posted. (I tested it, and it gives the undefined
sub error.) The second fix Gunnar suggested would produce an
error due to not returning true in test.pm. Without it, I bet
the OP is on a case-insensitive filesystem which has Test::Harness
installed. (Another reason not to name things test or Test.)

- --keith

- --
kkeller-
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (Darwin)

iD8DBQE/b8QDhVcNCxZ5ID8RAoTPAKCKoNlVmSH6LqsIPzyxRrLZwMKtFQ CeOXpd
iSvVZORrEPk23bbEUGikUiM=
=G9r6
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Jeff 'japhy' Pinyan
Guest
Posts: n/a
 
      09-23-2003
On 23 Sep 2003, Sam Holden wrote:

>On 22 Sep 2003 20:08:03 -0700,
> Great Deals <> wrote:
>> I put a file called test.pm in the same dir as test.pl
>>
>> test.pm:
>> #perl
>> package test;
>> sub getit (){
>> return time;
>> }
>>

>
>Since the test.pm above doesn't return a true value either aren't
>getting the error you specifiy below, or you aren't using the code
>you posted.


But we have no reason to believe that. Using the code he has, I can
reproduce the problem.

>> test.pl:
>> #perl
>> use test;
>>
>> $ab= test::getit();
>> print "$ab\n";
>>
>> the error is:
>> Undefined subroutine &test::getit called at test.pl line 4.

>
>There's not much point in fixing some random code that you aren't
>actually using.
>
>test.pm doesn't contain what you claim it does, or a different
>test.pm is getting included than the one you think is...


The second is the proper diagnosis. He is on Win32 (or some other OS that
has case-insensitive filenames). His program is using the Test.pm module,
rather than his local test.pm module.

--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

 
Reply With Quote
 
Jeff 'japhy' Pinyan
Guest
Posts: n/a
 
      09-23-2003
On 22 Sep 2003, Great Deals wrote:

>I put a file called test.pm in the same dir as test.pl


Don't name it test.pm. Name it MyTest.pm or some variant thereof. You're
using Windows, I bet, and your code is using the Perl standard Test.pm
module instead of the test.pm you wrote.

>test.pm:
>#perl
>package test;
>sub getit (){
>return time;
>}
>
>test.pl:
>#perl
>use test;
>
>$ab= test::getit();
> print "$ab\n";
>
>the error is:
>Undefined subroutine &test::getit called at test.pl line 4.


I know this because, with your code, on a Unix machine, I'd bet told that
test.pm doesn't return a true value during compilation. This is because
your module is missing the

1;

at the end, so that Perl knows everything went ok.

--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

 
Reply With Quote
 
Sam Holden
Guest
Posts: n/a
 
      09-23-2003
On Tue, 23 Sep 2003 01:23:20 -0400,
Jeff 'japhy' Pinyan <> wrote:
> On 23 Sep 2003, Sam Holden wrote:
>
>>On 22 Sep 2003 20:08:03 -0700,
>> Great Deals <> wrote:
>>> I put a file called test.pm in the same dir as test.pl
>>>
>>> test.pm:
>>> #perl
>>> package test;
>>> sub getit (){
>>> return time;
>>> }
>>>

>>
>>Since the test.pm above doesn't return a true value either aren't
>>getting the error you specifiy below, or you aren't using the code
>>you posted.

>
> But we have no reason to believe that. Using the code he has, I can
> reproduce the problem.


Since I don't get that error, I have a perfectly valid reason for
believing the code he posted wasn't the code he actually had.

Am I supposed to know the workings of every possible platform with every
possible set of module installs? I don't think that's reasonable.

I noticed the missing true return in the module, so I copied the code
into the file names he specified and tested it. And as I suspected,
got a different error message. I even did a perl -Mtest -e1 to see if
there was a test pragma I hadn't noticed before. What more do you
propose I do?

Stating the two reasons I can see for the problem seems a reasonably
helpful and useful answer.

Do I really have to test everything on all possible architectures before
I can take a guess at the cause of a problem? That's really going
to slow down any answers I might give as I hunt for a VMS machine to
test on.

--
Sam Holden

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-23-2003
Keith Keller wrote:
> In article <>, Sam
> Holden wrote:
>> There's not much point in fixing some random code that you aren't
>> actually using.
>>
>> test.pm doesn't contain what you claim it does, or a different
>> test.pm is getting included than the one you think is...

>
> If the latter, then certainly Great Deals could be using the code
> he posted. (I tested it, and it gives the undefined sub error.)
> The second fix Gunnar suggested would produce an error due to not
> returning true in test.pm. Without it, I bet the OP is on a
> case-insensitive filesystem which has Test::Harness installed.
> (Another reason not to name things test or Test.)


So that's why my "use lib '.';" suggestion makes a difference.

Choosing some other name for the module, as suggested by Jeff, is
obviously a better fix.

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

 
Reply With Quote
 
Keith Keller
Guest
Posts: n/a
 
      09-23-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

On 2003-09-23, Sam Holden <> wrote:
>
> Do I really have to test everything on all possible architectures before
> I can take a guess at the cause of a problem?


No, of course that's unreasonable. I think Jeff's point is that you
shouldn't accuse someone of not using the code he's posted unless you're
*sure* it couldn't produce the posted output. (e.g., an error like
$my=; shouldn't parse on any platform) You could even phrase it more
like a question: "Are you *sure* that's the code you're running? Here's
what I get...."

Some might contend that, while we shouldn't have to know every nuance
of every platform, popular problems like a case-insensitive filesystem
should be considered when reading about a problem you can't reproduce.
Obviously this is a grey area of problem-solving.

--keith

--
kkeller-
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj9wdXAACgkQhVcNCxZ5ID+HfACeKg6wDHMBT/kHVXjIHxI9H09C
mycAn0E773O5E1JL59x357FQ6MsgV20A
=8ZJq
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Great Deals
Guest
Posts: n/a
 
      09-23-2003
here is the working one: the 1st mistake i made was the test.pm, it
does not call my local test.pm but some default test.pm, secondly i
missed the

our @ISA=qw(Exporter);
our @EXPORT=qw (getit2);

test2.pm:
#!/usr/bin/perl -w
package test2;

use strict;
use Exporter;

our @ISA=qw(Exporter);
our $abc;
our @EXPORT=qw (getit2);

sub getit2{
return $abc;
}

1;
__END__

in test2.pl:

#!/usr/bin/perl -w
use test2;
$abc='123';
$ab= getit2;
print "$ab\n";
print getit2;


My questtion is
our @ISA=qw(Exporter);
our @EXPORT=qw (getit2);

a must thing to declare?

Secondly, how the module use the global value in main? I want to set a
value $abc to 123 in test2.pl, but I also want to get this value in
module in test2.pm. I don't want to pass the value as a parameter,
because I am still learning the passing by ref.

If in sub ($para1){$para1='new value'}, will the global value of para1
will changed? or once the sub is finished the value will be reset just
as using local or my?





(Great Deals) wrote in message news:< om>...
> I put a file called test.pm in the same dir as test.pl
>
> test.pm:
> #perl
> package test;
> sub getit (){
> return time;
> }
>
> test.pl:
> #perl
> use test;
>
> $ab= test::getit();
> print "$ab\n";
>
> the error is:
> Undefined subroutine &test::getit called at test.pl line 4.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Have I bought wrong product? enquirer Wireless Networking 2 06-10-2005 10:59 PM
Zero Config keeps connecting to the wrong AP =?Utf-8?B?ZGdyaWZmaXRo?= Wireless Networking 2 03-04-2005 05:52 PM
Is XML Doc wrong or is Schema wrong? (or both) Matthew XML 7 01-07-2005 10:05 PM
wrong connection status Peter Welk Wireless Networking 0 12-22-2004 03:26 PM
XP SP2 Wrong IP on connection D Wells Wireless Networking 3 12-09-2004 03:35 AM



Advertisments
 



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